Skip to content

Commit df45073

Browse files
📝 CodeRabbit Chat: Add comprehensive Jest unit tests for API, utils, and screen components
1 parent 11be213 commit df45073

File tree

9 files changed

+4316
-5
lines changed

9 files changed

+4316
-5
lines changed

frontend/api/groups.test.js

Lines changed: 901 additions & 0 deletions
Large diffs are not rendered by default.

frontend/babel.config.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
module.exports = function(api) {
2+
api.cache(true);
3+
return {
4+
presets: ['babel-preset-expo'],
5+
plugins: [
6+
['module-resolver', {
7+
alias: {
8+
'@': './src',
9+
},
10+
}],
11+
],
12+
};
13+
};

frontend/jest.setup.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Jest setup file for additional configuration
2+
import 'react-native-gesture-handler/jestSetup';
3+
4+
// Mock react-native modules that might cause issues in testing
5+
jest.mock('react-native/Libraries/Animated/NativeAnimatedHelper');
6+
7+
// Mock AsyncStorage
8+
jest.mock('@react-native-async-storage/async-storage', () =>
9+
require('@react-native-async-storage/async-storage/jest/async-storage-mock')
10+
);
11+
12+
// Mock react-navigation
13+
jest.mock('@react-navigation/native', () => {
14+
return {
15+
useNavigation: () => ({
16+
navigate: jest.fn(),
17+
goBack: jest.fn(),
18+
}),
19+
useRoute: () => ({
20+
params: {},
21+
}),
22+
};
23+
});
24+
25+
// Global test timeout
26+
jest.setTimeout(10000);

frontend/package.json

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@
66
"start": "expo start",
77
"android": "expo start --android",
88
"ios": "expo start --ios",
9-
"web": "expo start --web"
9+
"web": "expo start --web",
10+
"test": "jest",
11+
"test:watch": "jest --watch",
12+
"test:coverage": "jest --coverage"
1013
},
1114
"dependencies": {
1215
"@expo/metro-runtime": "~5.0.4",
@@ -26,7 +29,34 @@
2629
"react-native-web": "^0.20.0"
2730
},
2831
"devDependencies": {
29-
"@babel/core": "^7.20.0"
32+
"@babel/core": "^7.20.0",
33+
"jest": "^29.7.0",
34+
"@jest/environment-jsdom": "^29.7.0",
35+
"babel-jest": "^29.7.0"
3036
},
31-
"private": true
37+
"private": true,
38+
"jest": {
39+
"preset": "react-native",
40+
"testEnvironment": "jsdom",
41+
"setupFilesAfterEnv": [
42+
"<rootDir>/jest.setup.js"
43+
],
44+
"moduleFileExtensions": [
45+
"js",
46+
"jsx",
47+
"json"
48+
],
49+
"transform": {
50+
"^.+\\.(js|jsx)$": "babel-jest"
51+
},
52+
"testMatch": [
53+
"**/__tests__/**/*.(js|jsx)",
54+
"**/*.(test|spec).(js|jsx)"
55+
],
56+
"collectCoverageFrom": [
57+
"api/**/*.{js,jsx}",
58+
"!api/**/*.test.{js,jsx}",
59+
"!**/node_modules/**"
60+
]
61+
}
3262
}

0 commit comments

Comments
 (0)