# Code coverage report for lib/addons/__tests__/TestUtils-test.js

## Statements: 100% (45 / 45) Branches: 75% (6 / 8) Functions: 92.86% (13 / 14) Lines: 100% (43 / 43) Ignored: none

All files » lib/addons/__tests__/ » TestUtils-test.js

    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
    104
    105
    106
    107
    108

    1

    1

    1

    1

    1
    1
    1
    1
    1
    1

    1
    1

    1

    1

    1

    1
    1
    1

    1

    1
    1

    1
    1

    1

    1
    1

    1
    1

    1

    1
    1

    1
    1

    1

    1
    1

    1
    1
    1
    1

    1

    1
    6

     "use strict";

    var _interopRequire = function (obj) { return obj && obj.__esModule ? obj["default"] : obj; };

    var _interopRequireWildcard = function (obj) { return obj && obj.__esModule ? obj : { "default": obj }; };

    var TestUtils = _interopRequireWildcard(require("../TestUtils"));

    var sinon = _interopRequire(require("sinon"));

    describe("TestUtils", function () {
      describe("#simulateAction", function () {
        it("calls the stores handler", function () {
          var store = mockStore();
          var actionFunc = function () {};
          actionFunc._id = "actionFunc";

          TestUtils.simulateAction(store, "foo", "foo body");
          TestUtils.simulateAction(store, actionFunc, "actionFunc body");

          expect(store.handler.calledTwice).to.be["true"];

          expect(store.handler.getCall(0).args[0]).to.deep.equal({
            actionId: "foo",
            body: "foo body"
          });

          expect(store.handler.getCall(1).args[0]).to.deep.equal({
            actionId: "actionFunc",
            body: "actionFunc body"
          });
        });
      });

      describe("#simulateActionAsync", function () {
        it("it handles async begin", function () {
          var store = mockStore();

          TestUtils.simulateActionAsync(store, "foo", "begin");

          expect(store.handler.calledOnce).to.be["true"];
          expect(store.handler.firstCall.args[0]).to.deep.equal({
            actionId: "foo",
            async: "begin"
          });
        });

        it("it handles async begin w/ action args", function () {
          var store = mockStore();

          TestUtils.simulateActionAsync(store, "foo", "begin", "arg1", "arg2");

          expect(store.handler.calledOnce).to.be["true"];
          expect(store.handler.firstCall.args[0]).to.deep.equal({
            actionId: "foo",
            async: "begin",
            actionArgs: ["arg1", "arg2"]
          });
        });

        it("it handles async success", function () {
          var store = mockStore();

          TestUtils.simulateActionAsync(store, "foo", "success", { foo: "bar" });

          expect(store.handler.calledOnce).to.be["true"];
          expect(store.handler.firstCall.args[0]).to.deep.equal({
            actionId: "foo",
            async: "success",
            body: {
              foo: "bar"
            }
          });
        });

        it("it handles async failure", function () {
          var store = mockStore();

          TestUtils.simulateActionAsync(store, "foo", "failure", "error message");

          expect(store.handler.calledOnce).to.be["true"];
          expect(store.handler.firstCall.args[0]).to.deep.equal({
            actionId: "foo",
            async: "failure",
            error: "error message"
          });
        });

        it("it throws error with invalid asyncAction", function () {
          var store = mockStore();
          var simulate = function () {
            return TestUtils.simulateActionAsync(store, "foo", "fizbin");
          };

          expect(simulate).to["throw"]("asyncAction must be one of: begin, success or failure");
        });
      });
    });

    function mockStore() {
      return {
        handler: sinon.spy()
      };
    }
    //# sourceMappingURL=data:application/json;base64,