ampt-data-mock
TypeScript icon, indicating that this package has built-in type declarations

1.0.6 • Public • Published

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.

Readme

Keywords

none

Package Sidebar

Install

npm i ampt-data-mock

Weekly Downloads

1

Version

1.0.6

License

ISC

Unpacked Size

45.5 kB

Total Files

9

Last publish

Collaborators

  • tysoncadenhead