diff --git a/README.md b/README.md index a661061..b5d7545 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ If you have not found assertion framework/library that you are using - please ad - [Reduces repetitive code of test methods](#reduces-repetitive-code-of-test-methods); - [Simplifies initial setup](#simplifies-initial-setup); -### Allows to avoid re-testing nested action creators +### Allows to avoid retesting nested action creators It allows to test only actions that need to be tested. **Example:** diff --git a/src/README.md b/src/README.md index d2ba462..b5d7545 100644 --- a/src/README.md +++ b/src/README.md @@ -7,75 +7,29 @@ It use [redux-mock-store](https://github.com/arnaudbenard/redux-mock-store) to m [![build status](https://img.shields.io/travis/dmitry-zaets/redux-actions-assertions/master.svg?style=flat-square)](https://travis-ci.org/dmitry-zaets/redux-actions-assertions) [![npm version](https://img.shields.io/npm/v/redux-actions-assertions.svg?style=flat-square)](https://www.npmjs.com/package/redux-actions-assertions) -## What it does: -- [Simplifies initial setup](#simplifies-initial-setup); -- [Reduces repetitive code of test methods](#reduces-repetitive-code-of-test-methods); -- [Allows to avoid re-testing nested action creators](#allows-to-avoid-re-testing-nested-action-creators); - ## Supported Assertion Frameworks/Libraries: -- [chai](#chai) -- [expect](#expect) -- [expect.js](#expectjs) -- [should](#should) - -If you have not found assertion framework/library that you are using - you can use [pure javascript assertion](#javascript) or create an issue. - -### Simplifies initial setup -It provides singe-time global configuration for middlewares and initial store state. - -Without: -```javascript -const middlewares = [thunk]; -const mockStore = configureStore(middlewares); -const store = mockStore({ /*initial store object*}); -``` -With: -```javascript -registerMiddlewares([ thunk ]); -// to set custom initial state -registerInitialStoreState(/*object of function*/); -// to generate initial state of your application -registerInitialStoreState(buildInitialStoreState(/*your root reducer*/)); -``` - -### Reduces repetitive code of test methods -It reduces boilerplate of test methods and makes testing fluent. - -Without: -```javascript -const store = mockStore(/* initial state */); -const expectedActions = [ - { type: types.FETCH_TODOS_REQUEST }, - /* All expected triggered action objects */ -]; -store.dispatch(fetchData()).then(() => { - const actions = store.getActions(); - expect(actions).toEqual(expectedActions); -}).then(done).catch(done); -``` +- [chai](http://dmitry.js.org/redux-actions-assertions/chai.html) +- [expect](http://dmitry.js.org/redux-actions-assertions/expect.html) +- [expect.js](http://dmitry.js.org/redux-actions-assertions/expectjs.html) +- [should](http://dmitry.js.org/redux-actions-assertions/should.html) +- [pure javascript assertion](http://dmitry.js.org/redux-actions-assertions/javascript.html) -With: -```javascript -const expectedActions = [ - /*All expected triggered action objects or action creator functions*/ -]; -expect(fetchData()).toDispatchActions(expectedActions, done); -``` +If you have not found assertion framework/library that you are using - please add comment into [this issue](https://github.com/dmitry-zaets/redux-actions-assertions/issues/3). -With using customised store state: -```javascript -expect(fetchData()).withState({/*custom state*/}).toDispatchActions(expectedActions, done); -``` +## What it does: +- [Allows to avoid retesting nested action creators](#allows-to-avoid-retesting-nested-action-creators); +- [Reduces repetitive code of test methods](#reduces-repetitive-code-of-test-methods); +- [Simplifies initial setup](#simplifies-initial-setup); -### Allows to avoid re-testing nested action creators -It allows to test only actions that needs to be tested. +### Allows to avoid retesting nested action creators +It allows to test only actions that need to be tested. **Example:** We have two actions (A, B). Each one makes async http requests. -Action A makes request and if result is successful it triggers Action B. -Action B is also used as independent action. +Action A makes a request and if the result is successful it triggers Action B. +Action B is also used as an independent action. Action B can be tested separately. -We don't need to test it again in Action A. +Therefore, we don't need to test it again in Action A. Actions: ```javascript @@ -125,6 +79,53 @@ expect(actionA()).withState({ todos: [] }).toDispatch([ ], done); ``` +### Reduces repetitive code of test methods +It reduces boilerplate of test methods and makes testing fluent. + +Without: +```javascript +const store = mockStore(/* initial state */); +const expectedActions = [ + { type: types.FETCH_TODOS_REQUEST }, + /* All expected triggered action objects */ +]; +store.dispatch(fetchData()).then(() => { + const actions = store.getActions(); + expect(actions).toEqual(expectedActions); +}).then(done).catch(done); +``` + +With: +```javascript +const expectedActions = [ + /*All expected triggered action objects or action creator functions*/ +]; +expect(fetchData()).toDispatchActions(expectedActions, done); +``` + +With using customised store state: +```javascript +expect(fetchData()).withState({/*custom state*/}).toDispatchActions(expectedActions, done); +``` + +### Simplifies initial setup +It provides singe-time global configuration for middlewares and initial store state. + +Without: +```javascript +const middlewares = [thunk]; +const mockStore = configureStore(middlewares); +const store = mockStore({ /*initial store object*}); +``` +With: +```javascript +registerMiddlewares([ thunk ]); +// to set custom initial state +registerInitialStoreState(/*object of function*/); +// to generate initial state of your application +registerInitialStoreState(buildInitialStoreState(/*your root reducer*/)); +``` + ## Installation Using [npm](https://www.npmjs.org/): @@ -170,247 +171,4 @@ var registerInitialStoreState = reduxActionsAssertions.registerInitialStoreState // registration registerInitialStoreState(buildInitialStoreState(/* root reducer function */)); -``` - -## javascript - -### Registration - -For plain javasript assertions you dont need to register anything. Just import assertions in your tests: - -```js -// using ES6 modules -import assertions from 'redux-actions-assertions/assertions'; - -// using CommonJS modules -var assertions = require('redux-actions-assertions/assertions'); - -// in test -assertions.toDispatchActions(/**/) -assertions.toDispatchActionsWithState(/**/); -``` - -### Usage - -#### toDispatchActions -> `toDispatchActions(action, expectedActions, callback)` - -Asserts that when given `action` is dispatched it will dispatch `expectedActions`. `action` can be plain object (action) or function (action creator). `expectedActions` can be can be plain object (action) or function (action creator) or array of objects/functions. - -```js -toDispatchActions(testActionCreator(), [{ type: 'MY_ACTION_START' }], callback); -``` - -#### toDispatchActionsWithState - -> `toDispatchActionsWithState(initialState, action, expectedActions, callback)` - -Same as `toDispatchActions` + asserts that store initialised with `state` before `action` is dispatched. - -```js -toDispatchActions({property: 'value'}, testActionCreator(), [{ type: 'MY_ACTION_START' }], callback); -``` - -## [chai](https://github.com/chaijs/chai) - -### Registration - -```js -// using ES6 modules -import { registerAssertions } from 'redux-actions-assertions/chai'; - -// using CommonJS modules -var registerAssertions = require('redux-actions-assertions/chai').registerAssertions; - -// registration -registerAssertions(); -``` - -#### .to.dispatch.actions or assert.isDispatching - -> `expect(action).to.dispatch.actions(expectedActions, callback)` - -> `action.should.dispatch.actions(expectedActions, callback)` - -> `assert.isDispatching(action, expectedActions, callback)` - -Asserts that when given `action` is dispatched it will dispatch `expectedActions`. `action` can be plain object (action) or function (action creator). `expectedActions` can be can be plain object (action) or function (action creator) or array of objects/functions. - -```js -expect(myActionCreator()) - .to.dispatch.actions({ type: 'MY_ACTION_START' }, callback); - -myActionCreator() - .should.dispatch.actions({ type: 'MY_ACTION_START' }, callback); - -assert.isDispatching( - myActionCreator(), - { type: 'MY_ACTION_START' }, - callback -); -``` - -#### .with.state or assert.isDispatchingWithState - -> `expect(action).with.state(state).to.dispatch.actions(expectedActions, callback)` - -> `action.should.with.state(state).dispatch.actions(expectedActions, callback)` - -> `assert.isDispatchingWithState(action, expectedActions, state, callback)` - -Asserts that store initialised with `state` before `action` is dispatched. -```js -expect(myActionCreator()) - .with.state({ property: 'value' }) - .to.dispatch.actions([{ type: 'MY_ACTION_START' }, finishActionCreator()], callback); - -myActionCreator() - .should.with.({ property: 'value' }) - .dispatch.actions([{ type: 'MY_ACTION_START' }, finishActionCreator()], callback); - -assert.isDispatchingWithState( - myActionCreator(), - [{ type: 'MY_ACTION_START' }, finishActionCreator()], - { property: 'value' } - callback -); -``` - -## [expect](https://github.com/mjackson/expect) - -### Registration - -```js -// using ES6 modules -import { registerAssertions } from 'redux-actions-assertions/expect'; - -// using CommonJS modules -var registerAssertions = require('redux-actions-assertions/expect').registerAssertions; - -// registration -registerAssertions(); -``` -### Usage - -#### .toDispatchActions - -> `expect(action).toDispatchActions(expectedActions, callback)` - -Asserts that when given `action` is dispatched it will dispatch `expectedActions`. `action` can be plain object (action) or function (action creator). `expectedActions` can be can be plain object (action) or function (action creator) or array of objects/functions. - -```js -expect(myActionCreator()) - .toDispatchActions({ type: 'MY_ACTION_START' }, callback); -``` - -#### .withState - -> `expect(action).withState(state).toDispatchActions(expectedActions, callback)` - -Asserts that store initialised with `state` before `action` is dispatched. - -```js -expect(myActionCreator()) - .withState({property: 'value'}) - .toDispatchActions([{ type: 'MY_ACTION_START' }, finishActionCreator()], callback); -``` - -## [expect.js](https://github.com/Automattic/expect.js) - -### Registration - -```js -// using ES6 modules -import { registerAssertions } from 'redux-actions-assertions/expectjs'; - -// using CommonJS modules -var registerAssertions = require('redux-actions-assertions/expectjs').registerAssertions; - -// registration -registerAssertions(); -``` - -### Usage - -#### .dispatchActions - -> `expect(action).to.dispatchActions(expectedActions, callback)` - -Asserts that when given `action` is dispatched it will dispatch `expectedActions`. `action` can be plain object (action) or function (action creator). `expectedActions` can be can be plain object (action) or function (action creator) or array of objects/functions. - -```js -expect(myActionCreator()) - .to.dispatchActions({ type: 'MY_ACTION_START' }, callback); -``` - -#### .withState - -> `expect(action).withState(state).to.dispatchActions(expectedActions, callback)` - -Asserts that store initialised with `state` before `action` is dispatched. - -```js -expect(myActionCreator()) - .withState({ property: 'value' }) - .to.dispatchActions([{ type: 'MY_ACTION_START' }, finishActionCreator()], callback); -``` - -## [should](https://github.com/shouldjs/should.js) - -### Registration - -```js -// using ES6 modules -import { registerAssertions } from 'redux-actions-assertions/should'; - -// using CommonJS modules -var registerAssertions = require('redux-actions-assertions/should').registerAssertions; - -// registration -registerAssertions(); -``` - -### Usage - -#### .dispatchActions - -> `should(action).dispatchActions(expectedActions, callback)` -> `action.should.dispatchActions(expectedActions, callback)` - -Asserts that when given `action` is dispatched it will dispatch `expectedActions`. `action` can be plain object (action) or function (action creator). `expectedActions` can be can be plain object (action) or function (action creator) or array of objects/functions. - -```js -should(myActionCreator()) - .dispatchActions({ type: 'MY_ACTION_START' }, callback); - -myActionCreator().should - .dispatchActions({ type: 'MY_ACTION_START' }, callback); -``` - -#### .withState or with.state - -> `should(action).withState(state).dispatchActions(expectedActions, callback)` -> `should(action).with.state(state).dispatchActions(expectedActions, callback)` - -> `action.should.withState(state).dispatchActions(expectedActions, callback)` -> `action.should.with.state(state).dispatchActions(expectedActions, callback)` - -Asserts that store initialised with `state` before `action` is dispatched. - -```js -should(myActionCreator()) - .withState({ property: 'value' }) - .dispatchActions({ type: 'MY_ACTION_START' }, callback); - -should(myActionCreator()) - .with.state({ property: 'value' }) - .dispatchActions({ type: 'MY_ACTION_START' }, callback); - -myActionCreator().should - .withState({ property: 'value' }) - .dispatchActions({ type: 'MY_ACTION_START' }, callback); - -myActionCreator().should - .with.state({ property: 'value' }) - .dispatchActions({ type: 'MY_ACTION_START' }, callback); ``` \ No newline at end of file diff --git a/src/package.json b/src/package.json index 758a092..7a8fdc6 100644 --- a/src/package.json +++ b/src/package.json @@ -1,6 +1,6 @@ { "name": "redux-actions-assertions", - "version": "1.0.8", + "version": "1.1.0", "description": "Assertions for redux actions testing", "scripts": { },