You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I don't quite understand from documentation what approach to take for mocking transient dependencies.
Testing module A.ts in test A.spec.ts A.ts depends on rest-api.ts (which is auto-generated from a specification).
I need to mock rest-api.ts
In A.spec.ts if I just use rewiremock(() => import('rest-api'), {getData: () => Promise.resolve(mockdata)}) calling from A > rest.api during tests does not invoke the mocked rest-api function.
the mock function is invoked during the test!
Am I using the correct pattern here? I was under the impression the rewiremock would mock any module for the test via (1.) and mocking the module under test was not necessary?
The problem here is with import - by the time you run test it might not yet be configured and thus does nothing.
Consider using ‘require’ (will be not typesafe) if you need sync behaviour.
Hi Anton,
I don't quite understand from documentation what approach to take for mocking transient dependencies.
Testing module
A.ts
in testA.spec.ts
A.ts
depends onrest-api.ts
(which is auto-generated from a specification).I need to mock
rest-api.ts
A.spec.ts
if I just userewiremock(() => import('rest-api'), {getData: () => Promise.resolve(mockdata)})
calling from A > rest.api during tests does not invoke the mocked rest-api function.A
withthe mock function is invoked during the test!
Am I using the correct pattern here? I was under the impression the rewiremock would mock any module for the test via (1.) and mocking the module under test was not necessary?
Thanks for your insights.
Best, Ulrich
Sources:
https://itnext.io/unit-tests-for-skynet-written-in-js-6704265858a4
https://github.com/theKashey/rewiremock
The text was updated successfully, but these errors were encountered: