Coder Social home page Coder Social logo

reducer-tester's Introduction

reducer-tester

Build Status tested with jest styled with prettier All Contributors

reducer tester

See how-to-test-reducers

Install

$ yarn add --dev reducer-tester

Usage

// reducer.js
export const initialState = { count: 0, other: 'other' }

export default (state = initialState, action) => {
  switch (action.type) {
    case 'inc':
      return { ...state, count: state.count + 1 }
    case 'dec':
      return { ...state, count: state.count - 1 }
    default:
      return state
  }
}

// reducer.test.js
import reducerTester from 'reducer-tester'
import reducer, { initialState } from './reducer'

reducerTester({
  reducer,
  state: initialState,
  tests: [{ type: 'inc' }, { type: 'dec' }],
})

Snapshot

// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`handle initial state 1`] = `
"Snapshot Diff:
Compared values have no visual difference."
`;

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

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

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

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

Full example

import reducerTester from 'reducer-tester'
import reducer, { initialState } from './reducer'

reducerTester({
  reducer, // #required
  state: initialState, // #required
  tests: [{ type: 'inc' }, { type: 'dec' }], // #required
  initialTest: false, // # optional, default: true
  titlePrefix: 'handle ', // # optional, default: ''
})
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`handle dec 1`] = `
"Snapshot Diff:
- Before
+ After

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

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

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

Tips

Atom Editor User

Install language-diff and file-types. And open config.json and edit as blow.

"*":
  "file-types":
    "\\.js\\.snap$": "source.diff"

Hooray! Very readable!

68747470733a2f2f71696974612d696d6167652d73746f72652e73332e616d617a6f6e6177732e636f6d2f302f31353331392f64666537363137312d323735322d646265302d613038652d6330633436646330396264662e706e67 (495ร—575)

Contributors

Thanks goes to these wonderful people (emoji key):

akameco
akameco

๐Ÿ’ป ๐Ÿ“– โš ๏ธ ๐Ÿš‡
Ahn Dohyung
Ahn Dohyung

๐Ÿ“–
kinakobo
kinakobo

๐Ÿ“–

This project follows the all-contributors specification. Contributions of any kind welcome!

License

MIT ยฉ akameco

reducer-tester's People

Contributors

akameco avatar kinakobo avatar redshoga avatar renovate-bot avatar renovate[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

reducer-tester's Issues

Action Required: Fix Renovate Configuration

There is an error with this repository's Renovate configuration that needs to be fixed. As a precaution, Renovate will stop PRs until it is resolved.

Error type: Preset name not found within published preset config (@akameco)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.