Ivan - Add reducer test [skip ci]

This commit is contained in:
ivan 2016-08-13 23:59:39 -03:00
parent 922bc686bb
commit ccd491b41c
1 changed files with 56 additions and 0 deletions

View File

@ -0,0 +1,56 @@
const Reducer = require('reducers/reducer');
class SomeReducer extends Reducer {
getTypeHandlers() {
return {
'ACTION_1': this.handleAction1
};
}
getInitialState() {
return {
prop1: 0,
prop2: '',
prop3: false
};
}
handleAction1(state, payload) {
return {
state: state,
payload: payload,
prop1: 5,
prop2: 'hello',
prop3: true
};
}
}
describe('Reducer class', function () {
let reducer;
before(function () {
reducer = SomeReducer.getInstance();
});
it('should call correct handlers for each type', function () {
let result = reducer(undefined, {});
expect(result).to.deep.equal({
prop1: 0,
prop2: '',
prop3: false
});
result = reducer({prop4: true}, {type: 'ACTION_1', payload: 'PAYLOAD'});
expect(result).to.deep.equal({
state: {
prop4: true
},
payload: 'PAYLOAD',
prop1: 5,
prop2: 'hello',
prop3: true
});
});
});