JSPM

  • Created
  • Published
  • Downloads 2
  • Score
    100M100P100Q26554F
  • 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 unlimited nesting

Install

npm i mockital

Examples

Inspecting (Compatible with Jest Snapshots)
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";

// Jest
expect(inspect(Mock)).toMatchSnapshot();

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", []]]]]
        ]
      ]
    ]
  ];
Reset mock
const { mock, reset, inspect } = require("mockital");

const Mock = mock();

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

reset(Mock);

JSON.stringify(inspect(Mock)) === [];
Stubbing values
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";
Reset stubbed values
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;