UNPKG

2.22 kBJavaScriptView Raw
1import { expect } from 'chai';
2import { getActionTypes, SUCCESS_SUFFIX, ERROR_SUFFIX } from './../src/getActionTypes';
3
4describe('getActionTypes', () => {
5
6 it('should return default types with `type` key', () => {
7 const action = {type:'TYPE'};
8 const types = getActionTypes(action);
9 expect(types).to.be.array;
10 expect(types[0]).to.equal(action.type);
11 expect(types[1]).to.equal(`${action.type}${SUCCESS_SUFFIX}`);
12 expect(types[2]).to.equal(`${action.type}${ERROR_SUFFIX}`);
13 });
14
15 it('should return custom types with `types` key', () => {
16 const action = {
17 types:[
18 'TYPE',
19 'TYPE_AWESOME',
20 'TYPE_OH_NO'
21 ]
22 };
23 const types = getActionTypes(action);
24 expect(types).to.be.array;
25 expect(types[0]).to.equal(action.types[0]);
26 expect(types[1]).to.equal(`${action.types[1]}`);
27 expect(types[2]).to.equal(`${action.types[2]}`);
28
29 });
30
31 it('should throw if not type or types key received', () => {
32 const action = {};
33 expect(getActionTypes.bind(null,action)).to.throw(Error, /types/, /type/);
34 });
35
36 it('should use custom success sufix if defined', () => {
37 const action = {type:'TYPE'};
38 const types = getActionTypes(action, {successSuffix:'_AWESOME'});
39 expect(types).to.be.array;
40 expect(types[0]).to.equal(action.type);
41 expect(types[1]).to.equal(`${action.type}_AWESOME`);
42 expect(types[2]).to.equal(`${action.type}${ERROR_SUFFIX}`);
43 });
44
45 it('should use custom error sufix if defined', () => {
46 const action = {type:'TYPE'};
47 const types = getActionTypes(action, {errorSuffix:'_OH_NO'});
48 expect(types).to.be.array;
49 expect(types[0]).to.equal(action.type);
50 expect(types[1]).to.equal(`${action.type}${SUCCESS_SUFFIX}`);
51 expect(types[2]).to.equal(`${action.type}_OH_NO`);
52 });
53
54 it('should use custom success and error sufix if defined', () => {
55 const action = {type:'TYPE'};
56 const types = getActionTypes(action,{
57 successSuffix:'_AWESOME',
58 errorSuffix:'_OH_NO'
59 });
60 expect(types).to.be.array;
61 expect(types[0]).to.equal(action.type);
62 expect(types[1]).to.equal(`${action.type}_AWESOME`);
63 expect(types[2]).to.equal(`${action.type}_OH_NO`);
64 });
65
66});