redux-actions-assertions
Version:
Assertions for redux actions testing
49 lines (36 loc) • 1.78 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.registerAssertions = undefined;
var _should = require('should');
var _should2 = _interopRequireDefault(_should);
var _reduxActionsAssertionsJs = require('redux-actions-assertions-js');
var _actionWithInitialState = require('./actionWithInitialState');
var _actionWithInitialState2 = _interopRequireDefault(_actionWithInitialState);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function withState(state) {
this.obj = new _actionWithInitialState2.default(this.obj, state);
}
function dispatchActionsFunction(assert, assertWithState, expectedActions, done) {
if (this.obj instanceof _actionWithInitialState2.default) {
var action = this.obj.action;
var state = this.obj.state;
assertWithState(state, action, expectedActions, done);
} else {
assert(this.obj, expectedActions, done);
}
}
function dispatchActions(expectedActions, done) {
dispatchActionsFunction.call(this, _reduxActionsAssertionsJs.assertions.toDispatchActions, _reduxActionsAssertionsJs.assertions.toDispatchActionsWithState, expectedActions, done);
}
function notDispatchActions(expectedActions, done) {
dispatchActionsFunction.call(this, _reduxActionsAssertionsJs.assertions.toNotDispatchActions, _reduxActionsAssertionsJs.assertions.toNotDispatchActionsWithState, expectedActions, done);
}
function registerAssertions() {
_should2.default.Assertion.add('withState', withState);
_should2.default.Assertion.alias('withState', 'state');
_should2.default.Assertion.add('dispatchActions', dispatchActions);
_should2.default.Assertion.add('notDispatchActions', notDispatchActions);
}
exports.registerAssertions = registerAssertions;