Git Product home page Git Product logo

redux-duck-test's Introduction

Redux Duck Test

Helper functions for testing redux ducks made with redux-duck library.

Installation

npm i -D redux-duck-test

API

Test action type

import { testType } from 'redux-duck-test';
import { ADD } from '../duck/messages';

const result = testType({
  expected: ADD,
  actionName: 'ADD',
  duckName: 'messages',
  moduleName: 'my-app',
});
  • testType receive an object with the test specification.
  • The expected key is your action type.
  • The actionName key is the name of your action (eg. ADD).
  • The duckName key is the name of your duck (eg. messages).
  • The moduleName key is the name of your module (eg. my-app) (optional).

Test action creator

import { testAction } from 'redux-duck-test';
import { ADD, add } from '../duck/messages';

const result = testAction({
  actionCreator: add,
  payload: {
    id: 1,
    content: 'hello world!',
  },
  expected: {
    type: ADD,
    payload: {
      id: 1,
      content: 'hello world!',
    },
  },
});
  • testAction receive an object with the test specification.
  • The actionCreator key is the action creator function to test.
  • The payload key is the payload to send to the action creator.
  • The expected key is the expected action object.

Test reducer

import { testReducer } from 'redux-duck-test';
import { Map as map } from 'immutable';
import reducer, { add } from '../duck/messages';

const result = testReducer({
  reducer,
  state: map(),
  action: add({
    id: 1,
    content: 'hello world',
  }),
  expected: map({
    '1': {
      id: 1,
      content: 'hello world',
    },
  }),
});
  • testReducer receive an object with the test specification.
  • The reducer key is the reducer to test.
  • The state key is the initial state passed to the reducer.
  • The action key is the action to perform in the reducer.
  • The expected key is the expected next state.

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.