All files / xstate/test actionCreators.test.ts

100% Statements 31/31
100% Branches 0/0
100% Functions 11/11
100% Lines 31/31

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 1041x 1x   1x   1x 1x 2x 2x 2x 2x 2x                     2x 2x 2x 2x                     2x 2x         2x 2x                           1x 1x 1x 1x                 1x 1x 1x                 1x 1x 1x                 1x 1x 1x                    
import * as actions from '../src/actions';
import { assert } from 'chai';
 
const { actionTypes } = actions;
 
describe('action creators', () => {
  ['start', 'stop'].forEach(actionKey => {
    describe(`${actionKey}()`, () => {
      it('should accept a string action', () => {
        const action = actions[actionKey]('test');
        assert.equal(action.type, actionTypes[actionKey]);
        assert.deepEqual(action, {
          type: actionTypes[actionKey],
          exec: undefined,
          activity: {
            type: 'test',
            exec: undefined,
            id: 'test'
          }
        });
      });
 
      it('should accept an action object', () => {
        const action = actions[actionKey]({ type: 'test', foo: 'bar' });
        assert.equal(action.type, actionTypes[actionKey]);
        assert.deepEqual(action, {
          type: actionTypes[actionKey],
          exec: undefined,
          activity: {
            type: 'test',
            id: undefined,
            foo: 'bar'
          }
        });
      });
 
      it('should accept an activity definition', () => {
        const action = actions[actionKey]({
          type: 'test',
          foo: 'bar',
          src: 'someSrc'
        });
        assert.equal(action.type, actionTypes[actionKey]);
        assert.deepEqual(action, {
          type: actionTypes[actionKey],
          exec: undefined,
          activity: {
            type: 'test',
            id: undefined,
            foo: 'bar',
            src: 'someSrc'
          }
        });
      });
    });
  });
 
  describe('send()', () => {
    it('should accept a string event', () => {
      const action = actions.send('foo');
      assert.deepEqual(action, {
        target: undefined,
        type: actionTypes.send,
        event: { type: 'foo' },
        delay: undefined,
        id: 'foo'
      });
    });
 
    it('should accept an event object', () => {
      const action = actions.send({ type: 'foo', bar: 'baz' });
      assert.deepEqual(action, {
        target: undefined,
        type: actionTypes.send,
        event: { type: 'foo', bar: 'baz' },
        delay: undefined,
        id: 'foo'
      });
    });
 
    it('should accept an id option', () => {
      const action = actions.send('foo', { id: 'foo-id' });
      assert.deepEqual(action, {
        target: undefined,
        type: actionTypes.send,
        event: { type: 'foo' },
        delay: undefined,
        id: 'foo-id'
      });
    });
 
    it('should accept a delay option', () => {
      const action = actions.send('foo', { delay: 1000 });
      assert.deepEqual(action, {
        target: undefined,
        type: actionTypes.send,
        event: { type: 'foo' },
        delay: 1000,
        id: 'foo'
      });
    });
  });
});