Running Jest Tests in a Real Browser #6
Replies: 10 comments 8 replies
-
Thank you so much for the write up, Tom! I've got it working locally and so far everything is working great. |
Beta Was this translation helpful? Give feedback.
-
@jrylan no worries, happy to help! |
Beta Was this translation helpful? Give feedback.
-
I'm working on the same kind of setup for I'm struggling the |
Beta Was this translation helpful? Give feedback.
-
@Shingaz Just to so we're on the same page, what version of |
Beta Was this translation helpful? Give feedback.
-
I was trying with the latest one, I thought you managed to make it work with this one. It works with |
Beta Was this translation helpful? Give feedback.
-
For anyone else trying to get this working, this comment got everything working for me with the latest version of |
Beta Was this translation helpful? Give feedback.
-
From the blog post
@tom-sherman What do you use for mocking modules in your test setup? |
Beta Was this translation helpful? Give feedback.
-
@trivikr most of my code is pure with dependencies injected in. This allows me to pass in I don't think module mocking is possible in the browser without significant changes to jest internals. |
Beta Was this translation helpful? Give feedback.
-
This is how we write all our code on the backend side (Java): just pure and simple dependency injection via constructors. But this is highly unconventional in the Node/JS world as it would usually imply a big factory-style module at the top of the hierarchy wiring stuff up. For front-end code where one utilizes a lot of libraries, I see some major downsides to this, if you are going to pass down, say,
Module mocking in the browser level is not happening, unless browser vendors agree on implementing some loader hooks standard. To do mocking in the browser, it seems that one currently needs to do it at the webserver level, making aliases or import maps. Getting widespread tooling support for that does not seem to be happening anytime soon (but do let me know). |
Beta Was this translation helpful? Give feedback.
-
Is there by chance a fully working example of this setup somewhere? |
Beta Was this translation helpful? Give feedback.
-
https://github.com/tom-sherman/blog/blob/master/posts/02-running-jest-tests-in-a-browser.md
Questions, comments, criticisms below please 😄
Beta Was this translation helpful? Give feedback.
All reactions