-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
161 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,8 @@ | ||
jest.mock("react-native/Libraries/BatchedBridge/NativeModules", () => ({ | ||
ScreenshotAware: { | ||
mulitply: jest.fn(), | ||
addListener: jest.fn(), | ||
removeListeners: jest.fn(), | ||
}, | ||
PlatformConstants: {}, | ||
DeviceInfo: {}, | ||
})); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,58 @@ | ||
import { renderHook } from "@testing-library/react-native"; | ||
import { NativeEventEmitter } from "react-native"; | ||
import NativeScreenshotAware from "../codegenSpec/NativeScreenshotAware"; | ||
import { useScreenshotAware } from "../index"; | ||
import ScreenshotAware from "../index"; | ||
|
||
interface NativeModule { | ||
addListener: (event: string) => void; | ||
removeListeners: (count: number) => void; | ||
} | ||
|
||
const emitter = new NativeEventEmitter(NativeScreenshotAware); | ||
const typedEmitter = emitter as unknown as { _nativeModule: NativeModule }; | ||
|
||
describe("ScreenshotAware", () => { | ||
it("true", () => { | ||
expect(true).toBe(true); | ||
afterEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it("should add and remove listener in useScreenshotAware hook", () => { | ||
const callback = jest.fn(); | ||
const { unmount } = renderHook(() => useScreenshotAware(callback)); | ||
|
||
expect(typedEmitter._nativeModule.addListener).toHaveBeenCalledWith( | ||
"ScreenshotAwareEvent", | ||
); | ||
|
||
unmount(); | ||
expect(typedEmitter._nativeModule.removeListeners).toHaveBeenCalledWith(1); | ||
}); | ||
|
||
it("should call the callback when a screenshot event occurs", () => { | ||
const callback = jest.fn(); | ||
renderHook(() => useScreenshotAware(callback)); | ||
|
||
emitter.emit("ScreenshotAwareEvent"); | ||
|
||
expect(callback).toHaveBeenCalled(); | ||
}); | ||
|
||
it("should add and remove listener in ScreenshotAware module", () => { | ||
const callback = jest.fn(); | ||
const subscription = ScreenshotAware.addListener(callback); | ||
|
||
expect(typedEmitter._nativeModule.addListener).toHaveBeenCalledWith( | ||
"ScreenshotAwareEvent", | ||
); | ||
|
||
subscription.remove(); | ||
expect(typedEmitter._nativeModule.removeListeners).toHaveBeenCalledWith(1); | ||
}); | ||
|
||
it("should remove all listeners in ScreenshotAware module", () => { | ||
ScreenshotAware.removeAllListeners(); | ||
|
||
expect(typedEmitter._nativeModule.removeListeners).toHaveBeenCalled(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters