8000 GitHub - akameco/how-to-test-reducers
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

akameco/how-to-test-reducers

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

How to test reducers?

Of course, Test with Jest.

toEqual

src/toEqual.test.js

test('inc', () => {
  expect(reducer(initialState, { type: 'inc' })).toEqual({ count: 1, text: '' })
})

toMatchObject

src/toMatchObject.test.js

test('inc', () => {
  expect(reducer(initialState, { type: 'inc' })).toMatchObject({ count: 1 })
})

snapshot

src/toMatchObject.test.js

test('inc', () => {
  expect(reducer(initialState, { type: 'inc' })).toMatchSnapshot()
})

snapshot:

exports[`inc 1`] = `
Object {
  "count": 1,
  "text": "",
}
`;

snapshot-diff

src/snapshot-diff.test.js

test('inc', () => {
  expect(
    snapshotDiff(initialState, reducer(initialState, { type: 'inc' }))
  ).toMatchSnapshot()
})

snapshot:

exports[`inc 1`] = `
"Snapshot Diff:
- First value
+ Second value

  Object {
-   \\"count\\": 0,
+   \\"count\\": 1,
    \\"text\\": \\"\\",
  }"
`;

reducer-tester

src/reducer-tester.test.js

reducerTester({
  reducer,
  state: initialState,
  tests: [{ type: 'inc' }, { type: 'dec' }] // Just add any action...
})

snapshot:

exports[`inc 1`] = `
Snapshot Diff:
- Before
+ After

  Object {
-   "count": 0,
+   "count": 1,
    "text": "",
  }
`;

License

MIT © akameco

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published
0