Skip to content

Commit 0d2760d

Browse files
authored
Merge pull request #6 from oslabs-beta/snow/jest
Snow/jest
2 parents 323fd80 + f54f67f commit 0d2760d

File tree

3 files changed

+67
-1
lines changed

3 files changed

+67
-1
lines changed

__tests__/Readme.md

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# Testing
2+
3+
### Preparation
4+
5+
1. React Testing Library versions 13+ require React v18. If your project uses an older version of React, be sure to install version 12
6+
```
7+
npm install --save-dev @testing-library/react@12
8+
9+
```
10+
2. install additional packages
11+
```
12+
npm install -g jest
13+
npm i @jest/types
14+
npm i ts-jest
15+
npm i jest-environment-jsdom
16+
npm i --save-dev @types/jest
17+
npm i @types/node
18+
```
19+
3. create jest.config.js
20+
```
21+
module.exports = {
22+
verbose: true,
23+
setupFilesAfterEnv: ['./jest_setup/windowMock.js'],
24+
testEnvironment: "jsdom",
25+
preset: 'ts-jest/presets/js-with-ts',
26+
moduleNameMapper: {
27+
'\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$':
28+
'<rootDir>/jest_setup/fileMock.js',
29+
'\\.(css|less|scss)$': '<rootDir>/jest_setup/styleMock.js',
30+
},
31+
collectCoverage: true,
32+
types: ["jest","node"],
33+
};
34+
```
35+
4. make sure jest_setup folder is at root directory of Chronos with styleMock.js and windowMock.js
36+
37+
styleMock.js
38+
```
39+
module.exports = {};
40+
```
41+
windowMock.js
42+
```
43+
// Mock window environment
44+
window.require = require;
45+
46+
// Mock import statements for Plotly
47+
window.URL.createObjectURL = () => {};
48+
49+
// Mock get context
50+
HTMLCanvasElement.prototype.getContext = () => {};
51+
```
52+
5. update database info inside test_settings.json
53+
54+
6. use `npm run test` to run jest tests
55+
56+
### Contributing
57+
58+
Chronos hopes to inspire an active community of both users and developers. For questions, comments, or contributions, please submit a pull request.
59+
60+
### People
61+
[Snow X. Bai](https://github.com/xueapp)
62+
[Taylor Zhang](https://github.com/taylrzhang)
63+
[Tim Lee](https://github.com/timlee12)
64+
[Roberto Meloni](https://github.com/RobertoRueMeloni)

__tests__/test_settings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
[
44
"chronosDB",
55
"MongoDB",
6-
"mongodb+srv://troyprejusa:[email protected]/test?retryWrites=true&w=majority",
6+
"PUT YOUR MONGO URI HERE",
77
"",
88
"Dec 19, 2022 4:50 PM"
99
]

jest.config.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
module.exports = {
22
verbose: true,
33
setupFilesAfterEnv: ['./jest_setup/windowMock.js'],
4+
testEnvironment: "jsdom",
45
preset: 'ts-jest/presets/js-with-ts',
56
moduleNameMapper: {
67
'\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$':
78
'<rootDir>/jest_setup/fileMock.js',
89
'\\.(css|less|scss)$': '<rootDir>/jest_setup/styleMock.js',
910
},
1011
collectCoverage: true,
12+
types: ["jest","node"],
1113
};

0 commit comments

Comments
 (0)