aboutsummaryrefslogtreecommitdiff
path: root/test/shared/operations.test.ts
blob: 449b25e1b2c7bd9fbbc1db5be2094dd8f4c9ae93 (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
42
43
44
45
46
47
48
import * as operations from "../../src/shared/operations";
import { expect } from "chai";

describe("operations", () => {
  describe("#valueOf", () => {
    it("returns an Operation", () => {
      const op = operations.valueOf({
        type: operations.SCROLL_VERTICALLY,
        count: 10,
      }) as operations.ScrollVerticallyOperation;
      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", () => {
      const op = operations.valueOf({
        type: operations.COMMAND_SHOW_OPEN,
      }) as operations.CommandShowOpenOperation;

      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(() =>
        operations.valueOf({
          type: operations.COMMAND_SHOW_OPEN,
          alter: "true",
        })
      ).to.throw(TypeError);
    });
  });
});