Skip to content

Vestaboard/ampt-mock-data

Repository files navigation

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.