Skip to content

Instantly share code, notes, and snippets.

@sureshvv
Created August 26, 2023 06:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sureshvv/3c9825040be95692ae50181f537c9b39 to your computer and use it in GitHub Desktop.
Save sureshvv/3c9825040be95692ae50181f537c9b39 to your computer and use it in GitHub Desktop.
vi.spyOn does not work
==== example.js ====
function sub1() {
return 'hello'
}
function main1() {
return sub1()
}
export { sub1, main1 }
==== example.test.js ====
import { describe, expect, it, vi } from "vitest";
import * as api from './example'
describe('main', () => {
it("example", () => {
const spy1 = vi.spyOn(api, 'sub1')
api.main1()
expect(spy1).toHaveBeenCalledTimes(1)
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment