-
-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: added mock for
useKeyboardContext
(#361)
## 📜 Description Added mock for `useKeyboardContext` + `AndroidSoftInputModes`. ## 💡 Motivation and Context `useKeyboardContext` and `AndroidSoftInputModes` is a part of official API of this library. However they are not exported from the library (so if you use them in unit-test -> this test will not pass and you will have to mock it manually). So in this PR I'm adding them to mock and also adding a new unit test which assures that new mocks are actually present. ## 📢 Changelog ### JS - added mock for `useKeyboardContext`; - added mock for `AndroidSoftInputModes`. ## 🤔 How Has This Been Tested? Tested manually via newly added test. ## 📸 Screenshots (if appropriate): <img width="670" alt="image" src="https://github.com/kirillzyusko/react-native-keyboard-controller/assets/22820318/b3942088-344b-4f81-b64c-ea7e90be5c77"> ## 📝 Checklist - [x] CI successfully passed - [x] I added new mocks and corresponding unit-tests if library API was changed
- Loading branch information
1 parent
7d2d0a2
commit 620f379
Showing
7 changed files
with
145 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { useFocusEffect } from "@react-navigation/native"; | ||
import { renderHook } from "@testing-library/react-native"; | ||
import { useCallback } from "react"; | ||
import { | ||
AndroidSoftInputModes, | ||
KeyboardController, | ||
useKeyboardContext, | ||
} from "react-native-keyboard-controller"; | ||
|
||
jest.mock("@react-navigation/native", () => ({ | ||
useFocusEffect: jest.fn().mockImplementation((cb) => cb()), | ||
})); | ||
|
||
function useKeyboardAnimation() { | ||
useFocusEffect( | ||
useCallback(() => { | ||
KeyboardController.setInputMode( | ||
AndroidSoftInputModes.SOFT_INPUT_ADJUST_RESIZE, | ||
); | ||
|
||
return () => KeyboardController.setDefaultMode(); | ||
}, []), | ||
); | ||
|
||
const context = useKeyboardContext(); | ||
|
||
return context.animated; | ||
} | ||
|
||
describe("custom hook creation", () => { | ||
it("should render without errors", () => { | ||
const { result } = renderHook(() => useKeyboardAnimation()); | ||
|
||
expect(result).toBeDefined(); | ||
}); | ||
}); |
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
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 |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { useFocusEffect } from "@react-navigation/native"; | ||
import { renderHook } from "@testing-library/react-native"; | ||
import { useCallback } from "react"; | ||
import { | ||
AndroidSoftInputModes, | ||
KeyboardController, | ||
useKeyboardContext, | ||
} from "react-native-keyboard-controller"; | ||
|
||
jest.mock("@react-navigation/native", () => ({ | ||
useFocusEffect: jest.fn().mockImplementation((cb) => cb()), | ||
})); | ||
|
||
function useKeyboardAnimation() { | ||
useFocusEffect( | ||
useCallback(() => { | ||
KeyboardController.setInputMode( | ||
AndroidSoftInputModes.SOFT_INPUT_ADJUST_RESIZE, | ||
); | ||
|
||
return () => KeyboardController.setDefaultMode(); | ||
}, []), | ||
); | ||
|
||
const context = useKeyboardContext(); | ||
|
||
return context.animated; | ||
} | ||
|
||
describe("custom hook creation", () => { | ||
it("should render without errors", () => { | ||
const { result } = renderHook(() => useKeyboardAnimation()); | ||
|
||
expect(result).toBeDefined(); | ||
}); | ||
}); |
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
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