-
Notifications
You must be signed in to change notification settings - Fork 46
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Jest:moduleNameMapper: mocks do not work for imported modules of mapped modules using "moduleNameMapper" #936
Comments
Jest's "moduleNameMapper": {
"lazy&name=(.*)!": "<rootDir>/src/components/modals/$1.js"
} and later on import/require You can easily fix it by using wallaby.js cache folder path in the config: ...
setup: function (wallaby) {
const conf = require('./package.json').jest
const pattern = 'lazy&name=(.*)!'
conf.moduleNameMapper[pattern] = conf.moduleNameMapper[pattern].replace('<rootDir>', wallaby.projectCacheDir)
wallaby.testFramework.configure(conf)
} Let me know if this helps. |
wow that did it, thanks so much for your quick support! ...i by the way started using this and became a customer in one day--I couldn't be more impressed with the webpanel at ...one other thing--cuz im not sure where to submit ideas--but basically Wallaby seems to be the perfect fit for Jest and its snapshot testing. It's a match made in heaven being able to browse your snapshots in a UI, rather than the command line (or after you commit code and can diff it). It allows u to diff code in a proper UI rather than in the terminal while you're editing. That said what would be perfect is if in the top right column of the web panel, the DIFF was shown by default rather than having to click that little icon in the top right and see it in a modal. After all, that's exactly what you want to see. The all red info of the failed result that you already have is obviously a lot harder to read. In addition, if you even showed successful snapshots, rather than just nothing, that would go a long way toward making Wallaby the defacto best (and only?) Jest snapshot browser--sometimes you just want to review how snapshots are looking; and if this was there, you'd be doing it a lot more often; it would become an effective part of you're workflow. To make it consistent with non-snapshots, just show the test file there too so you can click file names in the left column, and not have to perform a second click where you click the eye-ball. That would be a better overall user experience imho--because it would have you doing less switching of your attention from the wallaby panel and your editor. Why not just be instantly reminded of what tests are in each file, rather than having to click the eye-ball which you otherwise only do when you need to. LAST THING: Add a button to update a snapshot right there in that top right box (so you don't have to run jest from the command line and annoyingly type out the testPathPattern of the file), and it's everything Jest is missing. You can now easily update a single snapshot, rather than worry you're updating too many by not specifying specific test patterns in the terminal. With all that, you've completed the Jest feedback loop! I'm going to recommend everyone use Jest and Wallaby. Again, match made in heaven! |
@faceyspacey Wow, thanks for the feedback, I appreciate it! |
@ArtemGovorov ...sorry to bother u again, one last thing: why no inline values within tests besides for It's not a new idea at this point and I'm sure you're very aware of the idea--so that's why I'm assuming performance is the only reason you haven't done it--but basically if you guys had this (and tables containing values for loops), it would be the first useable implementation for javascript when not explicitly debugging, which itself has never been truly stable like it is in Chrome devtools. Like, the workflow you got here--rather, I got here now ;)--is utterly amazing, and very stable. It's the first time TDD in javascript UI work has made actual sense. It's just annoying to have to type If performance is the problem, maybe if just the current test function you're working on has values displayed, or ideally at least the currently focused/open file. |
@faceyspacey We did consider the idea early on, but the performance (everyone wants their tests to run as fast as possible), a lot of possible visual noise, inline message length limitations and a few other things are holding us off. The performance can get really bad if doing the full trace values recording. Few years ago I have been doing it in spy-js and only for function params and return values, still had a significant performance impact. For capturing just the latest values it can be pretty fast (see "Spy-js Magnifier"), but the approach has its own issues in the context of running unit tests. With all this experience, we are now prototyping some best of both worlds lightweight debugging workflows, so may of the things you're asking may be covered there, so feel free to subscribe to that feature request and stay tuned :) |
Done: https://twitter.com/wallabyjs/status/819121381002489856 |
@ArtemGovorov that is absolutely excellent. it's working already for me. The way you deliver is by far the best/fastest I've ever seen. Something tells me it's because you're eating your own dogfood ;) |
Issue description or question
If you map your modules in the Jest config file like this:
And then one of your tests mocks a module used by a mapped module like this:
And then the mapped module you're testing imports
Button
like this:/src/components/modals/file.js:
Button
will NOT be mocked.I've tested the regular scenario without using
moduleNameMapper
and the mock works just fine. Awesome! It only seems to break down when the moduleNameMapper dynamically chooses the module for you statically.The hoisting-related issue and solution using
babel-preset-jest
does not solve that (that didn't do anything and you don't seem to need that anymore, as regular mocks work without it).It just appears that wallaby is not able to discover mocks for your own files (or perhaps there's a special config I'm not privy to) when using the module mapper.
Also note: mocked NPM modules such as
jest.mock('npm-module', () => require('identity-obj-proxy'))
works just fine.Wallaby.js configuration file
Code editor or IDE name and version
Visual Studio Code v1.8
OS name and version
OSX
The text was updated successfully, but these errors were encountered: