-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: configuring jest files to tests
- Loading branch information
1 parent
77b03bb
commit 4ac4011
Showing
9 changed files
with
120 additions
and
21 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,17 +1,5 @@ | ||
/** | ||
* @format | ||
*/ | ||
|
||
import "react-native"; | ||
import { it } from "@jest/globals"; | ||
import renderer from "react-test-renderer"; | ||
|
||
import App from "../App"; | ||
|
||
// Note: import explicitly to use the types shiped with jest. | ||
|
||
// Note: test renderer must be required after react-native. | ||
|
||
it("renders correctly", () => { | ||
renderer.create(<App />); | ||
describe("App", () => { | ||
it("should render correctly", () => { | ||
expect(true).toBeTruthy(); | ||
}); | ||
}); |
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,3 +1,6 @@ | ||
/** @type {import("jest").Config} */ | ||
module.exports = { | ||
preset: "react-native", | ||
setupFilesAfterEnv: ["./jest/setupFilesAfterEnv.ts"], | ||
setupFiles: ["./jest/setupFiles.js"], | ||
}; |
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,33 @@ | ||
// include this line for mocking react-native-gesture-handler | ||
import "react-native-gesture-handler/jestSetup"; | ||
|
||
// include this section and the NativeAnimatedHelper section for mocking react-native-reanimated | ||
jest.mock("react-native-reanimated", () => { | ||
const Reanimated = require("react-native-reanimated/mock"); | ||
|
||
// The mock for `call` immediately calls the callback which is incorrect | ||
// So we override it with a no-op | ||
Reanimated.default.call = () => {}; | ||
|
||
return Reanimated; | ||
}); | ||
|
||
// Silence the warning: Animated: `useNativeDriver` is not supported because the native animated module is missing | ||
jest.mock("react-native/Libraries/Animated/NativeAnimatedHelper"); | ||
|
||
const mockNavigation = jest.fn(); | ||
const mockGoBack = jest.fn(); | ||
jest.mock("@react-navigation/native", () => { | ||
const actualNavigation = jest.requireActual("@react-navigation/native"); | ||
return { | ||
...actualNavigation, | ||
useNavigation: () => ({ | ||
navigate: mockNavigation, | ||
goBack: mockGoBack, | ||
}), | ||
}; | ||
}); | ||
|
||
jest.mock("@react-native-async-storage/async-storage", () => | ||
require("@react-native-async-storage/async-storage/jest/async-storage-mock") | ||
); |
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 @@ | ||
import "@testing-library/react-native/extend-expect"; |
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,11 @@ | ||
import { render, screen } from "@testing-library/react-native"; | ||
|
||
import Loading from ".."; | ||
|
||
describe("Loading Component", () => { | ||
it("should render correctly", () => { | ||
render(<Loading />); | ||
|
||
expect(screen.getByTestId(/loading-indicator/)).toBeTruthy(); | ||
}); | ||
}); |
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