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

mocking zapatos in unit tests #176

Open
leoschweizer opened this issue Jun 20, 2024 · 0 comments
Open

mocking zapatos in unit tests #176

leoschweizer opened this issue Jun 20, 2024 · 0 comments

Comments

@leoschweizer
Copy link

This is basically an open question to all zapatos users: how do you mock zapatos in unit tests? I'm currently trying to find a setup for esm and the native node test runner. The obvious approach of

import { mock } from 'node:test'
import * as db from 'zapatos/db'

mock.method(db, 'select')

does not work due to:

  TypeError [Error]: Cannot redefine property: select
      at defineProperty (<anonymous>)
      at MockTracker.method (node:internal/test_runner/mock/mock:404:5)

Previously I successfully used jest, but want to get rid of it:

jest.mock('zapatos/db', () => {
    const original = jest.requireActual('zapatos/db')
    return {
        ...original,
        select: jest.fn(),
    }
})

The native module mocking is still experimental in node and I did not have any success with that either.

So, how do you do it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant