Skip to main content
Deno 2 is finally here ๐ŸŽ‰๏ธ
Learn more
Module

x/unitest/matcher/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/matcher/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();
});

Parameters

unnamed 0: MockObject