1.0.6 • Published 5 months ago

ampt-data-mock v1.0.6

Weekly downloads
-
License
ISC
Repository
-
Last release
5 months ago

AMPT Data Mock

Mocks to do unit testing against fake @ampt/data in memory.

Installation

# NPM
npm i ampt-data-mock --dev

# Yarn
yarn add ampt-data-mock --save-dev

Usage With Jest

At the top of your test, just mock @ampt/data with the export from this library.

import { data } from "ampt-data-mock";

jest.mock("@ampt/data", () => ({
  data,
}));

describe("My tests", () => {
  it("Should do a thing", async () => {
    // Bootstrap the data with any keys you need to create beforehand...
    await data.set("key", { value: "foo" });

    // Your tests...
  });
});

Resetting

Since this package persists data in memory, it is best practice to reset the data before each unit test using the reset() function

import { data, reset } from "ampt-data-mock";

jest.mock("@ampt/data", () => ({
  data,
}));

describe("My tests", () => {
  beforeEach(() => {
    reset();
  });

  // ...
});

Notes

This is still a work in progress. The goal is to support all of the Ampt data API in memory, but we are starting with the simple use-cases.

This is an independently maintained repo and is not owned or operated by Ampt in any way.

1.0.6

5 months ago

1.0.5

8 months ago

1.0.4

9 months ago

1.0.3

9 months ago

1.0.2

9 months ago

1.0.1

9 months ago

1.0.0

10 months ago