Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

more mock APIs #186

Closed
5 of 14 tasks
sheremet-va opened this issue Dec 16, 2021 · 2 comments
Closed
5 of 14 tasks

more mock APIs #186

sheremet-va opened this issue Dec 16, 2021 · 2 comments
Labels
enhancement New feature or request

Comments

@sheremet-va
Copy link
Member

sheremet-va commented Dec 16, 2021

https://jestjs.io/docs/27.2/jest-object#mock-modules

extending #185

  • jest.disableAutomock()
  • jest.enableAutomock()
  • jest.createMockFromModule()/jest..getMockFromModule(moduleName) -> use vi.mock or vi.importMock
  • jest.mock(moduleName, factory, options)
  • jest.doMock(moduleName, factory, options) - not supported, since static imports won't work then. if you need dynamic import, you can use vi.importMock. may support in the future if needed
  • jest.unmock(moduleName) / jest.dontMock(moduleName)
  • jest.setMock(moduleName, moduleExports) -> use vi.mock
  • jest.requireActual(moduleName) -> vi.importActual
  • jest.requireMock(moduleName) -> vi.importMock
  • jest.mocked<T>(item: T, deep = false)

Current vitest implementation does not support automocking, so these functions are left out:

  • jest.disableAutomock() - not sure if we should support automocking, it's a very confusing feature for users
  • jest.enableAutomock()

Not really a part of this issue:

  • jest.resetModules()
  • jest.isolateModules(fn)
@antfu antfu added the enhancement New feature or request label Dec 20, 2021
@eratio08
Copy link

eratio08 commented Dec 28, 2021

Maybe support for class/interface mocking like with jest-mock-extended

interface PartyProvider {
   getPartyType: () => string;
   getSongs: (type: string) => string[]
   start: (type: string) => void;
}

const mock = mock<PartyProvider>();

@sheremet-va
Copy link
Member Author

sheremet-va commented Dec 28, 2021

Maybe support for class/interface mocking like with jest-mock-extended

interface PartyProvider {
   getPartyType: () => string;
   getSongs: (type: string) => string[]
   start: (type: string) => void;
}

const mock = mock<PartyProvider>();

I think this is an interesting idea, but not a part of this issue, I'm afraid. If you want this to be implemented, you can create another issue. We can discuss it there. For now closing this, since all APIs are implemented now.

@github-actions github-actions bot locked and limited conversation to collaborators Jun 24, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants