Fakultas Ilmu Komputer UI

Commit 9d299fab authored by Ahmad Izzudin Alifyandra's avatar Ahmad Izzudin Alifyandra
Browse files

Merge branch 'setup-jest' into 'master'

Setup Jest files and Enable Coverage

See merge request !62
parents 4ca0e2a0 f8e22e9d
...@@ -10,6 +10,7 @@ npm-debug.* ...@@ -10,6 +10,7 @@ npm-debug.*
web-build/ web-build/
/ios /ios
.env .env
jest/coverage
# macOS # macOS
.DS_Store .DS_Store
...@@ -8,7 +8,6 @@ npm-debug.* ...@@ -8,7 +8,6 @@ npm-debug.*
*.mobileprovision *.mobileprovision
*.orig.* *.orig.*
web-build/ web-build/
/config
/ios /ios
# macOS # macOS
......
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
import "react-native-gesture-handler/jestSetup";
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;
});
jest.mock("@react-navigation/core", () => {
const actualNav = jest.requireActual("@react-navigation/core");
return {
...actualNav,
useNavigation: () => ({
navigate: jest.fn(),
dispatch: jest.fn(),
}),
};
});
// Silence the warning: Animated: `useNativeDriver` is not supported because the native animated module is missing
jest.mock("react-native/Libraries/Animated/src/NativeAnimatedHelper");
...@@ -12,7 +12,19 @@ ...@@ -12,7 +12,19 @@
"prepare": "husky install" "prepare": "husky install"
}, },
"jest": { "jest": {
"preset": "jest-expo" "preset": "jest-expo",
"setupFiles": [
"<rootDir>/jest/setup.js"
],
"coverageDirectory": "jest/coverage/",
"collectCoverage": true,
"collectCoverageFrom": [
"**/*.{jsx,ts,tsx}",
"!**/coverage/**",
"!**/node_modules/**",
"!**/babel.config.js",
"!**/jest.setup.js"
]
}, },
"dependencies": { "dependencies": {
"@expo/vector-icons": "^12.0.0", "@expo/vector-icons": "^12.0.0",
...@@ -63,10 +75,11 @@ ...@@ -63,10 +75,11 @@
"eslint-plugin-react-hooks": "^4.2.0", "eslint-plugin-react-hooks": "^4.2.0",
"husky": "^7.0.2", "husky": "^7.0.2",
"jest": "^27.2.0", "jest": "^27.2.0",
"jest-expo": "~41.0.0-beta.0", "jest-expo": "^42.1.0",
"lint-staged": "^11.1.2", "lint-staged": "^11.1.2",
"prettier": "^2.4.0", "prettier": "^2.4.0",
"react-test-renderer": "^17.0.2", "react-test-renderer": "^17.0.2",
"redux-mock-store": "^1.5.4",
"typescript": "~4.0.0" "typescript": "~4.0.0"
}, },
"private": true, "private": true,
......
import { cleanup, render, fireEvent } from "@testing-library/react-native"; import { cleanup, render, fireEvent } from "@testing-library/react-native";
import FirebaseConfig from "../../../../config/firebase"; import FirebaseConfig from "../../../../config/firebase";
import firebase from "firebase/app"; import firebase from "firebase/app";
// import "firebase/firestore"; import "firebase/firestore";
afterEach(cleanup); afterEach(cleanup);
...@@ -11,9 +11,9 @@ describe("Basic Firebase Tests", () => { ...@@ -11,9 +11,9 @@ describe("Basic Firebase Tests", () => {
}); });
// TODO : shows firestore connection error // TODO : shows firestore connection error
// it("Successfully query Firestore", async () => { it("Successfully query Firestore", async () => {
// const db = firebase.firestore(); const db = firebase.firestore();
// const query = await db.collection("test").get(); const query = await db.collection("test").get();
// expect(query.metadata).not.toBeNull(); expect(query.metadata).not.toBeNull();
// }); });
}); });
/* eslint-disable @typescript-eslint/no-unsafe-call */
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
import { render } from "@testing-library/react-native"; import { render } from "@testing-library/react-native";
import Register from "../../../screens/auth/RegisterScreen"; import Register from "../../../screens/auth/RegisterScreen";
import React from "react"; import React from "react";
import { Provider } from "react-redux";
import configureStore from "redux-mock-store";
describe("Register Screen Test", () => { describe("Register Screen Test", () => {
it("Renders Form", () => { it("Renders Form", () => {
const mockStore = configureStore();
const { getAllByPlaceholderText } = render( const { getAllByPlaceholderText } = render(
<Register navigation={null} route={null} /> <Provider store={mockStore({ name: "alif" })}>
<Register navigation={null} route={null} />
</Provider>
); );
expect(getAllByPlaceholderText("Masukkan Nama Depan")); expect(getAllByPlaceholderText("Masukkan Nama Depan"));
expect(getAllByPlaceholderText("Masukkan Nama Belakang")); expect(getAllByPlaceholderText("Masukkan Nama Belakang"));
......
// TODO add tests for image functions
This diff is collapsed.
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment