Issue with custom moduleNameMapper for Jest
ferrannp opened this issue · 0 comments
ferrannp commented
In an internal project I try to add a new rule in my package.json
like:
"jest": {
moduleNameMapper": {
"\\.(html)$": "<rootDir>/fileMock.js"
}
}
I see the property gets properly merge but my test keeps failing. I tried directly in test.js
, if I do it like:
moduleNameMapper['\\.(html)$'] = `${TEST_MOCKS_PATH}/fileMock.js`;
// We map webpack aliases from webpack-isomorphic-tools-config file
// so Jest can detect them in tests too
Object.keys(aliases).forEach((key) => {
moduleNameMapper[`^${key}(.*)$`] = `${aliases[key]}$1`;
});
My test passes. However, if I place it right after like:
// We map webpack aliases from webpack-isomorphic-tools-config file
// so Jest can detect them in tests too
Object.keys(aliases).forEach((key) => {
moduleNameMapper[`^${key}(.*)$`] = `${aliases[key]}$1`;
});
moduleNameMapper['\\.(html)$'] = `${TEST_MOCKS_PATH}/fileMock.js`;
Then my test fails. The order should not matter so I am wondering if html
is hitting another rule under aliases.