mockital

0.6.15 • Public • Published

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;

Readme

Keywords

Package Sidebar

Install

npm i mockital

Weekly Downloads

0

Version

0.6.15

License

unlicense

Unpacked Size

13.7 kB

Total Files

18

Last publish

Collaborators

  • rubixibuc