Skip to main content
Module

x/unitest/mod.ts>toHaveBeenCalledOnce

🃏 Deno-first universal unit testing framework
Latest
function toHaveBeenCalledOnce
Re-export
import { toHaveBeenCalledOnce } from "https://deno.land/x/unitest@v1.0.0-beta.82/mod.ts";

Use .toHaveBeenCalledOnce to check if a mock object was called exactly one time

import {
  defineExpect,
  fn,
  not,
  test,
  toHaveBeenCalledOnce,
} from "https://deno.land/x/unitest@$VERSION/mod.ts";

const expect = defineExpect({
  matcherMap: {
    toHaveBeenCalledOnce,
  },
  modifierMap: {
    not,
  },
});

test("passes only if mock object was called exactly once", () => {
  const mockObject = fn();

  mockObject();
  expect(mockObject).toHaveBeenCalledOnce();
  mockObject();
  expect(mockObject).not.toHaveBeenCalledOnce();
});