# Code coverage report for lib/addons/TestUtils.js

## Statements: 100% (23 / 23) Branches: 100% (8 / 8) Functions: 100% (3 / 3) Lines: 100% (23 / 23) Ignored: none

All files » lib/addons/ » TestUtils.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

    1

    1
    1
    2
    2
    1
    5
    4

    5
    5

    5

    2
    1

    2

    1
    1

    1
    1

    1

    4

    1
    7

    1

     "use strict";

    /**
     * Used for simulating actions on stores when testing.
     *
     */
    exports.simulateAction = simulateAction;

    /**
     * Used for simulating asynchronous actions on stores when testing.
     *
     * asyncAction must be one of the following: begin, success or failure.
     *
     * When simulating the 'begin' action, all arguments after 'begin' will
     * be passed to the action handler in the store.
     *
     * @example
     *
     * TestUtils.simulateActionAsync(store, 'actionId', 'begin', 'arg1', 'arg2');
     * TestUtils.simulateActionAsync(store, 'actionId', 'success', { foo: 'bar' });
     * TestUtils.simulateActionAsync(store, 'actionId', 'failure', new Error('action failed'));
     */
    exports.simulateActionAsync = simulateActionAsync;
    function simulateAction(store, action, body) {
      var actionId = ensureActionId(action);
      store.handler({ actionId: actionId, body: body });
    }function simulateActionAsync(store, action, asyncAction) {
      for (var _len = arguments.length, args = Array(_len > 3 ? _len - 3 : 0), _key = 3; _key < _len; _key++) {
        args[_key - 3] = arguments[_key];
      }

      var actionId = ensureActionId(action);
      var payload = {
        actionId: actionId, async: asyncAction
      };

      switch (asyncAction) {
        case "begin":
          if (args.length) {
            payload.actionArgs = args;
          }
          break;
        case "success":
          payload.body = args[0];
          break;
        case "failure":
          payload.error = args[0];
          break;
        default:
          throw new Error("asyncAction must be one of: begin, success or failure");
      }

      store.handler(payload);
    }

    function ensureActionId(actionOrActionId) {
      return typeof actionOrActionId === "function" ? actionOrActionId._id : actionOrActionId;
    }
    Object.defineProperty(exports, "__esModule", {
      value: true
    });
    //# sourceMappingURL=data:application/json;base64,