Open bennyk8y opened 1 year ago
similar issues with Sinon stub/spy:
TypeError: Descriptor for property myFunctionName is non-configurable and non-writable
The issue is related to https://github.com/swc-project/swc-node/issues/700
In previous major version @swc-node/jest@1.5.5 mocks are working right
I'm expecting that https://github.com/swc-project/swc-node/pull/714 will fix the problem
Please, check the latest version
no change for Sinon
@rosmcmahon I wrote up a small answer on SO on how you can generally use Sinon alongside Quibble (or any other similar tool, like Proxyquire) to mock modules when running SWC. Assumes your target module type is "commonjs".
yeah, catching up on this again. basically sinon recognising that swc is building the module exports in a more correct way, but that it's out of scope for their project to support this.
The problem is that Jest is a combination of many things:
By itself, nether Jest nor Sinon can know that an object is a module with exports and what you want to do with it 🤷 Both require the user to know what they are looking at.
thanks @fatso83, sorry for the delay.
yeah, i was adding swc to an older codebase of mine. the solution was to remove swc, and revert to transpileOnly
with type-checking step.
IMO if i'm using proxyquire then i'm doing something wrong as i should write my code with testing in mind. i even avoid stubs these days
In the article I have out for review I discuss three different approaches to exactly this issue, one of which is the tool independent route of exposing ways of injecting dependencies. I guess you are doing something similar to what I propose there?
Would really like some extra set of eyes on this, so if you could spare five minutes I can perhaps help quite a few people in avoiding the trouble you experienced 🙏
Hi, this is
jest.config.template.js
:this is the test file:
result an error of
TypeError: _getBankTransaction.getBankTransactionOrFail.mockResolvedValueOnce is not a function
.using ts-jest preset works as expected
versions: "@swc-node/jest": "1.6.5", "jest": "28.1.3"