Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit de043c3

Browse files
committed
feat: add enzyme and enzyme-to-json for jest snapshot serialization using enzyme, update README for new test structure/style
1 parent a13a4e4 commit de043c3

File tree

5 files changed

+410
-20
lines changed

5 files changed

+410
-20
lines changed

‎README.md

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -186,14 +186,17 @@ higher. If you experience errors, please upgrade your version of Node.js.
186186

187187
The default testing framework is Jest, though you can use whatever you want.
188188

189-
Tests should reside alongside the modules they are testing:
189+
Tests and their corresponding files such as Jest snapshots, should be co-located
190+
alongside the modules they are testing, in a `spec/` folder. For example:
190191

191192
```
192-
├── server
193-
│ ├── api
194-
│ │ ├── todos
195-
│ │ │ ├── todos.controller.js
196-
│ │ │ ├── todos.controller.test.js
193+
├── components
194+
│ ├── todos
195+
│ │ ├── TodoForm
196+
│ │ │ ├── spec
197+
│ │ │ │ ├── TodoForm.test.js
198+
│ │ │ ├── index.js
199+
│ │ │ ├── index.scss
197200
```
198201

199202
Tests can be written with ES2015, since it passes through `babel-register`.

‎jest.config.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,17 @@ const moduleAliasesMap = mapValues(
66
mapKeys(_moduleAliases, (_, alias) => `${alias}/(.*)$`),
77
path => `<rootDir>/${path}/1ドル`
88
);
9-
const staticFiles = '\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|'
10-
+ 'webm|wav|mp3|m4a|aac|oga)$';
9+
1110
const cssFiles = '\\.(css|scss|less)$';
11+
const staticFiles =
12+
'\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|' +
13+
'webm|wav|mp3|m4a|aac|oga)$';
1214

1315
module.exports = {
1416
verbose: true,
1517
moduleFileExtensions: ['js', 'jsx'],
18+
snapshotSerializers: ['enzyme-to-json/serializer'],
19+
setupTestFrameworkScriptFile: '<rootDir>/jest.setup.js',
1620
moduleNameMapper: {
1721
...moduleAliasesMap,
1822
[staticFiles]: '<rootDir>/__mocks__/fileMock.js',

‎jest.setup.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
const { configure } = require('enzyme');
2+
const Adapter = require('enzyme-adapter-react-16');
3+
4+
// configure an adapter for enzyme
5+
configure({ adapter: new Adapter() });

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /