redux-simple-test-recorder
v0.0.3
Published
Redux Simple Test Recorder for Redux
Downloads
2
Readme
redux-simple-test-recorder
Simple Test Recorder for Redux
Installation
npm install redux-simple-test-recorder --save
Usage
The first thing that you need to do is to create a test generator function that is suitable for your application, here's an example for a tape test:
const reducer = (state, {type, payload}) => {
...
};
const testGenerator = (actions) => {
const asserts = actions.map((action, index) => {
return `test('${action.action.type} (action index ${index}) should correctly update state', function(assert) {
var action = actions[${index}];
var result = reducer(action.prevState, action.action);
assert.ok(equality(result, action.nextState), 'state updated correctly');
assert.end();
});`
}).join('\n\n');
return (`
var test = require('tape');
${reducer.toString()}
var equality = (result, nextState) => JSON.stringify(result) === JSON.stringify(nextState);
var actions = ${JSON.stringify(actions, null, 2)};
${asserts}`
);
};
Than you should build and use the middleware in your store
import reduxRecord from 'redux-simple-test-recorder';
const record = reduxRecord(testGenerator);
export const store = createStore(reducer, applyMiddleware(record.middleware));
export const recordInterface = record.recordInterface;
Now you can use the record interface to start recording your tests
recordInterface.startRecord();
//Do something on the UI...
const test = recordInterface.stopRecord();
console.log(test);
Enjoy your generated tests! :)
License
This software is licensed under the WTFPL license. For more information, see the LICENSE file in this repository.