JSPM

  • Created
  • Published
  • 0
  • Score
    100M100P100Q16721F
  • License unlicense

mock anything

Package Exports

  • mockital

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (mockital) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

MOCKITAL 🦸

Build Status Coverage Status

  • Supports gets, sets, new, and invocation
  • Supports nested everything

More utilities are coming for inspecting/asserting/stubbing

Perfect for snapshot testing mocks with Jest

Install

npm i mockital

Examples

Reset mock new
const { mock, reset, inspect } = require("mockital");

const Mock = mock();

Mock.a.b.c("1", "2", "3");

reset(Mock);

JSON.stringify(inspect(Mock)) === [];
Reset stubbed values new
const { mock, resetWhen, when } = require("mockital");

const Mock = mock();

when("a", mock().a.b.c("1", "2", "3"), Mock);

resetWhen(Mock);

// stubbed value no longer returned
Mock.a.b.c("1", "2", "3").d.e;
Stubbing values (NEW)
const { mock, when } = require("mockital");

const Mock = mock();

when("a", mock().a.b.c("1", "2", "3"), Mock);

Mock.a.b.c("1", "2", "3") === "a";
Inspecting
const { mock, inspect } = require("mockital");

const Mock = mock();

Mock.a = "is this is amazing?";

const wow = new Mock.b.c["c"](1, "2", [1, 2]);

wow.d.e(1, 2, 3).f = "this is amazing";

JSON.stringify(inspect(Mock)) ===
  [
    ["set", "a", "is this is amazing?", []],
    [
      "get",
      "b",
      [
        [
          "get",
          "c",
          [
            [
              "get",
              "c",
              [
                [
                  "new",
                  [1, "2", [1, 2]],
                  [
                    [
                      "get",
                      "d",
                      [
                        [
                          "get",
                          "e",
                          [
                            [
                              "apply",
                              [1, 2, 3],
                              [["set", "f", "this is amazing", []]]
                            ]
                          ]
                        ]
                      ]
                    ]
                  ]
                ]
              ]
            ]
          ]
        ]
      ]
    ]
  ];
JSON.stringify(inspect(wow)) ===
  [
    [
      "get",
      "d",
      [
        [
          "get",
          "e",
          [["apply", [1, 2, 3], [["set", "f", "this is amazing", []]]]]
        ]
      ]
    ]
  ];