Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

redux-testkit

Package Overview
Dependencies
Maintainers
1
Versions
33
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

redux-testkit - npm Package Compare versions

Comparing version 0.1.12 to 0.1.13

8

dist/ActionTest.js

@@ -97,2 +97,6 @@ Object.defineProperty(exports,"__esModule",{value:true});exports.ActionTest=undefined;var _createClass=function(){function defineProperties(target,props){for(var i=0;i<props.length;i++){var descriptor=props[i];descriptor.enumerable=descriptor.enumerable||false;descriptor.configurable=true;if("value"in descriptor)descriptor.writable=true;Object.defineProperty(target,descriptor.key,descriptor);}}return function(Constructor,protoProps,staticProps){if(protoProps)defineProperties(Constructor.prototype,protoProps);if(staticProps)defineProperties(Constructor,staticProps);return Constructor;};}();var _lodash=require('lodash');var _lodash2=_interopRequireDefault(_lodash);function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{default:obj};}function _possibleConstructorReturn(self,call){if(!self){throw new ReferenceError("this hasn't been initialised - super() hasn't been called");}return call&&(typeof call==="object"||typeof call==="function")?call:self;}function _inherits(subClass,superClass){if(typeof superClass!=="function"&&superClass!==null){throw new TypeError("Super expression must either be null or a function, not "+typeof superClass);}subClass.prototype=Object.create(superClass&&superClass.prototype,{constructor:{value:subClass,enumerable:false,writable:true,configurable:true}});if(superClass)Object.setPrototypeOf?Object.setPrototypeOf(subClass,superClass):subClass.__proto__=superClass;}function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError("Cannot call a class as a function");}}var

}},{key:'getParam',value:function getParam()
{
}}]);return Dispatched;}();var

@@ -112,2 +116,6 @@

return this.action;
}},{key:'getParam',value:function getParam(
name){
return this.getParams()[name];
}}]);return DispatchedObject;}(Dispatched);var

@@ -114,0 +122,0 @@

2

package.json
{
"name": "redux-testkit",
"version": "0.1.12",
"version": "0.1.13",
"description": "Test kit for redux",

@@ -5,0 +5,0 @@ "author": "Yedidya Kennard <yedidyak@gmail.com>",

@@ -12,7 +12,17 @@ # redux-testkit

### What's Included?
* [Actions Unit Tests using ActionTest](#usage---actions)
* [Reducers Unit Tests using ReducerTest](#usage---reducers)
* [Integration Tests using WaitForAsyncsMiddleware](#usage---waitforasyncsmiddleware)
### Usage - Actions
To import the module in your test file, use
`import {ActionTest} from 'redux-testkit';`
To make usage of the module in your test file, import and instantiate it:
```js
import {ActionTest} from 'redux-testkit';
const actionTest = new ActionTest();
```
ActionTest provides these methods:

@@ -24,3 +34,3 @@

```
```js
beforeEach(() => {

@@ -41,3 +51,3 @@ actionTest.reset();

```
```js
export function actionToTest(parameters) {

@@ -69,18 +79,20 @@ return async function(dispatch, getState) {

```js
expect(actionTest.getDispatched(0).isPlainObject()). toBeTrue();
expect(actionTest.getDispatched(0).getType()).toEqual(actionTypes.ACTION_TYPE_1);
expect(actionTest.getDispatched(0).getParams().otherField).toEqual({some object});
// Note: getParam() can be used instead of getParams() as a convenience:
expect(actionTest.getDispatched(0).getParam('otherField')).toEqual({some object});
```
expect(getDispatched(0).isPlainObject()). toBeTrue();
expect(getDispatched(0).getType()).toEqual(actionTypes.ACTION_TYPE_1);
expect(getDispatched(0).getParams().otherField).toEqual({some object});
```
In case 2, the `name` of the dispatched function is saved, and can be tested like this
```js
expect(actionTest.getDispatched(1).isFunction()).toBeTrue();
expect(actionTest.getDispatched(1).getName()).toEqual('name_of_function');
```
expect(uut.getDispatched(1).isFunction()).toBeTrue();
expect(uut.getDispatched(1).getName()).toEqual('name_of_function');
```
**If this is another thunk, then you must name the internal anonymous async function, like this:**
```
```js
export function name_of_function() {

@@ -94,6 +106,6 @@ return async function name_of_function(dispatch, getState) {

```
```js
const result = actions.syncAction(actionTest.mockDispatch, actionTest.getState(), params...);
expect(result).toEqual(123456);
expect(uut.getDispatched()).to....
expect(actionTest.getDispatched()).to....
```

@@ -131,3 +143,49 @@

### Usage - WaitForAsyncsMiddleware
a Helpful middleware for running integration tests that include thunk actions.
If you want to test a complex flow in your app from end to end that has nested thunk actions calls, async calls and more, use it.
To import the module in your test file, use
`import {WaitForAsyncsMiddleware} from 'redux-testkit';`
WaitForAsyncsMiddleware provides these methods:
#### createMiddleware()
Creates a redux middleware that captures all async actions and allows you to wait till they are all resolved.
```js
beforeEach(() => {
const WaitForMiddleware = WaitForAsyncsMiddleware.createMiddleware();
store = createStore(combineReducers(reducers), applyMiddleware(WaitForMiddleware, thunk));
});
```
#### waitForPendingAsyncs()
This method will wait for all current pending action promises (async calls).
It will also wait for the subsequence async actions that were called as a result of the resolve of any prior async action.
It will finish once all recursive async action calls were resolved.
```js
it('test async action flow', async () => {
store.dispatch(thunkActionThatCallOtherThunkActions());
await WaitForAsyncsMiddleware.waitForPendingAsyncs();
expect(store.getState().expectedData).toBeDefined();
});
```
#### reset()
This method will reset the array of pending async action calls were captured.
reset is being called every time you call `createMiddleware` method.
```js
beforeEach(() => {
WaitForAsyncsMiddleware.reset();
});
```
## TODO
[ ] Improve syntax with Matchers - Please open issues to suggest the syntax you'd want!

@@ -98,2 +98,6 @@ import _ from 'lodash';

}
getParam() {
//
}
}

@@ -113,2 +117,6 @@

}
getParam(name) {
return this.getParams()[name];
}
}

@@ -115,0 +123,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc