Open AdrienLemaire opened 6 years ago
Current hack was to create a src/__mocks__/js-snackbar.js
file with the following content:
jest.mock("js-snackbar");
export const show = jest.fn().mockImplementation(config => config);
IMO would be better if you could just publish valid javascript files instead of transpiled ones :) https://github.com/thymikee/jest-preset-angular#adjust-your-transformignorepatterns-whitelist
@Fandekasp - thanks for putting this together, definitely agree on valid JS files. Will work on getting this updated in a new release soon.
To clarify, are you using version 1.1.0?
1.0.1 ! Will upgrade by next week, sorry about that.
no worries at all :), just wanted to double check.
@johnrhampton js-snackbar v1.1.2 , and still getting errors when removing the mock dir
SyntaxError: Unexpected token export
2 |
3 | import "js-snackbar/snackbar.css";
> 4 | import {show} from "js-snackbar";
| ^
5 | import {COLORS} from "~/constants";
6 |
7 | const messageMap = {
at ScriptTransformer._transformAndBuildScript (node_modules/jest-runtime/build/script_transformer.js:403:17)
at Object.<anonymous> (src/snackbar.js:4:1)
@Fandekasp, I can add a transpiled module option. Another quick thought, have you tried adding something similar to your jest config?
"transformIgnorePatterns": [
"node_modules/?!(js-snackbar)"
]
When trying to run my jest tests after integrating js-snackbar, I got the error
Tried to set the following config in package.json:
Then got the following error:
I tried to add more settings like
But then the first error re-appears as if the transformIgnorePatterns rule is bypassed
If trying to map both files:
I get yet another error
Any idea what would be the right way to remove errors related to js-snackbar when running jest ? The ideal would be having snackbars mocked to keep unit tests fast.