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
Test cases are picking the required subject module from the cache. Hence they don't get the mocked instances of functions/modules that have been replaced using td.replace().
Manually deleting the entry from require.cache solves it. And the next require() call correctly picks up the mocked references. Also such issues occur only when the entire test suite is run, running individual tests don't seem to cause such problems
Issue: General question
As per this section in docs, having td.replace() and require() in the beforeEach() block bypasses module cache, but for some reason this doesn't seem to work in my setup
// test.js
// other tests
describe('Testing module A', () => {
let depModule, subject
beforeEach(() => {
depModule = require('path/to/depModule')
let mockedFn = td.replace(depModule, 'depFn')
subject = require('path/to/subjectModule') // refers to original depFn
})
afterEach(() => {
td.reset()
})
// it blocks
)
To fix this I am currently maunally deleting references from require.cache. Like below:
Description
Test cases are picking the required subject module from the cache. Hence they don't get the mocked instances of functions/modules that have been replaced using
td.replace()
.Manually deleting the entry from
require.cache
solves it. And the nextrequire()
call correctly picks up the mocked references. Also such issues occur only when the entire test suite is run, running individual tests don't seem to cause such problemsIssue: General question
As per this section in docs, having
td.replace()
andrequire()
in the beforeEach() block bypasses module cache, but for some reason this doesn't seem to work in my setupTo fix this I am currently maunally deleting references from require.cache. Like below:
I would like to understand in such cases what is the cause usually? and if any there are better ways to deal with it?
P.S.: Please correct me if this is not the correct channel for queries
The text was updated successfully, but these errors were encountered: