aboutsummaryrefslogtreecommitdiff
path: root/test/shared/operations.test.ts
blob: 42a3eeda44fd4eb5f1d7f6589e8d0c93e29bfdbe (plain) (blame)
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
import * as operations from 'shared/operations';

describe('operations', () => {
  describe('#valueOf', () => {
    it('returns an Operation', () => {
      let op: operations.Operation = operations.valueOf({
        type: operations.SCROLL_VERTICALLY,
        count: 10,
      });
      expect(op.type).to.equal(operations.SCROLL_VERTICALLY);
      expect(op.count).to.equal(10);
    });

    it('throws an Error on missing required parameter', () => {
      expect(() => operations.valueOf({
        type: operations.SCROLL_VERTICALLY,
      })).to.throw(TypeError);
    });

    it('fills default valus of optional parameter', () => {
      let op: operations.Operation = operations.valueOf({
        type: operations.COMMAND_SHOW_OPEN,
      });

      expect(op.type).to.equal(operations.COMMAND_SHOW_OPEN)
      expect(op.alter).to.be.false;
    });

    it('throws an Error on mismatch of parameter', () => {
      expect(() => operations.valueOf({
        type: operations.SCROLL_VERTICALLY,
        count: '10',
      })).to.throw(TypeError);

      expect(() => valueOf({
        type: operations.COMMAND_SHOW_OPEN,
        alter: 'true',
      })).to.throw(TypeError);
    });
  });
})