npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

chai-redux

v1.0.2

Published

Chai Helper for testing (async) redux stores

Downloads

50

Readme

Chai Redux

This is an extension plugin for chai assertion library for testing redux stores.

Because testing should be as easy as:

const store = chai.createReduxStore({reducer, middleware: [thunk]});
// when
store.dispatch(fetchData());
// then
expect(store).to.eventually.have
    .dispatched('FETCH')
    .then.dispatched(
        {type: 'SUCCESSFUL', name: 'redux'})
    .notify(done);

For more insights read Why I created chai-redux

Install

Required peer dependencies:

  • chai >= 1.1.0
  • redux >= 3.1.3
$ npm run install chai-redux

Setup

import chai from 'chai'
import chaiRedux from 'chai-redux'

chai.use(chaiRedux)

API

Creating Store

chai.createReduxStore({reducer, middlewares, initialState)})

Arguments:

  1. reducer (Function, Object):
    1.1 Function: A reducing function that returns the next state tree, given the current state tree and an action to handle.
    1.2 Object: An object whose values correspond to different reducing functions that need to be combined into one.
  2. middlewares ([Function]) : Optional functions that conform to the Redux middleware API.
  3. initialState (Object): initial state of store

Example

import chai, { expect } from 'chai';
import chaiRedux from '../src';
import thunk from 'redux-thunk';
import reducerA from '//';
import reducerB from '//';

chai.use(chaiRedux);

describe('create test store', () => {

    it('should create store', () => {
        const store = chai.createReduxStore({
            reducer: {
                a: reducerA,
                b: reducerB
            },
            middlewares: [thunk],
            initialState: {a: {/* ... /*}, b: {/* ... /*}}
        });
    });

});

Assertions

.state(state: any)

Asserts that store state history contains state, using deep equal.

expect(store).to.have.state({loading: false, value: null});
expect(store).not.to.have.state({loading: false, value: null});
expect(store).to.have
    .state({loading: false, value: null})
    .and.state({loading: true, value: 42});

.state.like(state: any)

Asserts that store state history contains state, using partial deep comparison.

expect(store).to.have.state.like({loading: false});
expect(store).to.have
    .state.like({value: null})
    .and.state.like({value: 42});

.then.state(state: any)

Asserts that state is next state in state history.

expect(store).to.have
    .state({loading: false})
    .then.state({loading: true});

then.state and then.dispatched cannot be mixed.

.dispatched(action: String, Object)

Asserts that store action history contains action, using partial deep comparison.

expect(store).to.have
    .dispatched({type: 'LOAD'});
expect(store).to.have
    .dispatched('LOAD');

.then.dispatched(state: any)

Asserts that state is next state in state history.

expect(store).to.have
    .dispatched('LOAD')
    .then.dispatched({type: 'RESET'});

then.state and then.dispatched cannot be mixed.

.eventually, .notify(done: function)

Asserts that history contains state or action. It will wait till store history contains state or action. Once state is found done is notified.

expect(store).to.have.eventually
    .state({loading: false, value: null})
    .and.state.like({loading: true})
    .and.dispatched('LOAD')
    .notify(done);
// test
store.dispatch({type: 'LOAD'});

License

chai-redux is Open Source software released under the Apache 2.0 license.