Skip to content

Commit 3f31e14

Browse files
committed
feat: unit test integration
1 parent 3df5d56 commit 3f31e14

File tree

5 files changed

+95
-51
lines changed

5 files changed

+95
-51
lines changed

jest.config.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import type { Config } from '@jest/types';
2+
3+
const config: Config.InitialOptions = {
4+
verbose: true,
5+
transform: {
6+
'^.+\\.tsx?$': 'ts-jest',
7+
},
8+
moduleNameMapper: {
9+
'@/(.*)': '<rootDir>/src/$1',
10+
},
11+
};
12+
13+
export default config;

package-lock.json

Lines changed: 54 additions & 49 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,17 @@
99
"preview": "vite preview",
1010
"lint": "eslint --ignore-path .eslintignore --ext .ts,.tsx .",
1111
"format": "prettier --ignore-path .gitignore --write \"**/*.+(ts|tsx|json)\"",
12+
"test": "jest",
1213
"release": "standard-version"
1314
},
1415
"dependencies": {
1516
"@hookform/resolvers": "^2.9.7",
17+
"@tanstack/react-query": "^4.0.10",
1618
"axios": "^0.25.0",
1719
"concurrently": "^7.0.0",
1820
"react": "^18.2.0",
1921
"react-dom": "^18.2.0",
2022
"react-hook-form": "^7.34.0",
21-
"react-query": "^4.0.0",
2223
"react-router": "^6.2.1",
2324
"react-router-dom": "^6.3.0",
2425
"react-toastify": "^8.2.0",
@@ -29,6 +30,7 @@
2930
"devDependencies": {
3031
"@commitlint/cli": "^16.2.1",
3132
"@commitlint/config-conventional": "^16.2.1",
33+
"@types/jest": "^28.1.6",
3234
"@types/node": "^17.0.21",
3335
"@types/react": "^18.0.15",
3436
"@types/react-dom": "^18.0.6",
@@ -39,9 +41,11 @@
3941
"eslint-config-prettier": "^8.3.0",
4042
"eslint-plugin-react": "^7.28.0",
4143
"husky": "^7.0.4",
44+
"jest": "^28.1.3",
4245
"prettier": "^2.5.1",
4346
"sass": "^1.49.0",
4447
"standard-version": "^9.3.2",
48+
"ts-jest": "^28.0.7",
4549
"typescript": "^4.4.4",
4650
"vite": "^2.7.2"
4751
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { login } from '../auth.service';
2+
3+
describe('login', () => {
4+
it('should return true on successfull login', async () => {
5+
const body = { username: 'user', password: 'user' };
6+
const res = await login(body);
7+
expect(res).toBe(true);
8+
});
9+
10+
it('should throw error message on failed login', async () => {
11+
expect.assertions(1);
12+
try {
13+
const body = { username: 'user', password: 'wrong' };
14+
await login(body);
15+
} catch (err) {
16+
expect(err).toMatch('Invalid username or password');
17+
}
18+
});
19+
});

tsconfig.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@
1818
"resolveJsonModule": true,
1919
"isolatedModules": true,
2020
"noEmit": true,
21-
"types": ["node"],
21+
"types": [
22+
"node",
23+
"jest",
24+
],
2225
"jsx": "react-jsx",
2326
"baseUrl": "src",
2427
"paths": {

0 commit comments

Comments
 (0)