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

redux-action-asserter

v1.1.2

Published

## Why Does This Exist?

Downloads

14

Readme

Redux Test Action Log Middleware

Why Does This Exist?

I found myself using redux-mock-store a lot when writing semi-integrated tests, where I was testing a connected component inside a react-redux Provider. This works great when you're interacting with the store directly, but is less useful when you're writing tests that set up more than one connected component and want to test their interaction with at least partial isolation.

The benefit of this middleware is that it lets you use your actual store configuration, updating state, and re-rendering connected components with new props, but also assert on sync or async actions.

Installation

npm install redux-test-action-log --save-dev

Usage

While this module provides a redux middleware, it exists as a constructor with a few extra features. This gives you access to the assertion functions and encapsulates the action log between tests.

import {createStore, applyMiddleware} from 'redux'
import ActionAsserter from 'redux-action-asserter'

const actionAsserter = new ActionAsserter()

// Basic no-op test reducer. You would typically use your application reducer her
const myReducer = state => state
const store = createStore(myReducer, applyMiddleware(actionAsserter.middleware()))

// ...Do some stuff that dispatches normal actions
actionAsserter.getActions()
// -> [an, array, of, dispatched, actions]

If you're using the redux-thunk middleware, you can also use resolve to create a thennable that will resolve when all dispatched thunks have resolved. Note to use this feature, your thunk must return a Promise.

import {createStore, applyMiddleware} from 'redux'
import thunk from 'redux-thunk'
import ActionAsserter from 'redux-action-asserter'

const actionAsserter = new ActionAsserter()

// Basic no-op test reducer. You would typically use your application reducer her
const myReducer = state => state
const store = createStore(myReducer, applyMiddleware(thunk, actionAsserter.middleware()))

const afterAsyncAction = {type: 'after-async'}
const myThunk = () => dispatch => {
  return Promise.resolve().then(() => {
    dispatch(afterAsyncAction)
  })
}
store.dispatch(myThunk())

actionAsserter.resolve().then(() => {
  store.getActions()
  // [afterAsyncAction]
})