From 39ce95c0d0ea556b0ccd792b68c6247fdbfd2a60 Mon Sep 17 00:00:00 2001 From: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> Date: Tue, 24 Oct 2023 06:21:14 -0700 Subject: [PATCH] Add test for spyOn + ESM namespace --- test/js/bun/test/mock/mock-module.test.ts | 10 +++++++++- test/js/bun/test/mock/spymodule-fixture.ts | 3 +++ 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 test/js/bun/test/mock/spymodule-fixture.ts diff --git a/test/js/bun/test/mock/mock-module.test.ts b/test/js/bun/test/mock/mock-module.test.ts index 04e5779ddb..c4c6188351 100644 --- a/test/js/bun/test/mock/mock-module.test.ts +++ b/test/js/bun/test/mock/mock-module.test.ts @@ -7,8 +7,16 @@ // - Write test for export {foo} from "./foo" // - Write test for import {foo} from "./foo"; export {foo} -import { mock, test, expect } from "bun:test"; +import { mock, test, expect, spyOn, Mock } from "bun:test"; import { fn, iCallFn, variable } from "./mock-module-fixture"; +import * as spyFixture from "./spymodule-fixture"; + +test("spyOn", () => { + spyOn(spyFixture, "iSpy"); + expect(spyFixture.iSpy).not.toHaveBeenCalled(); + spyFixture.iSpy(123); + expect(spyFixture.iSpy).toHaveBeenCalled(); +}); test("mocking a local file", async () => { expect(fn()).toEqual(42); diff --git a/test/js/bun/test/mock/spymodule-fixture.ts b/test/js/bun/test/mock/spymodule-fixture.ts new file mode 100644 index 0000000000..b11761d630 --- /dev/null +++ b/test/js/bun/test/mock/spymodule-fixture.ts @@ -0,0 +1,3 @@ +export function iSpy(_) { + return 42; +}