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
New install not working with Jest #1071
Comments
Pretender does not work in node. This makes mirageJS (when using pretender) only available to run in a browser. You can use try to use If you would like to user import { Server } from 'miragejs';
import MswInterceptor from 'mirage-msw';
new Server({
// your config options
interceptor: new MswInterceptor(),
}); |
Thanks @cah-brian-gantzler, I guess I'm confused? The docs have info on Jest and unit testing which I assumed meant it would work in JSDom? |
If you read the comparison page is does say that MirageJS only works in the browser. Could you tell me where in the docs it talks about Jest? The tests for this package does use jest, and Im wondering if that is what you are seeing. The unit tests are testing this package, not using this package in another application. All those tests are running in the browser. |
@cah-brian-gantzler sorry for the delay in responding, the tutorial walks through using it with Jest: |
@snaptopixel Are you using jsdom, if so, what version? |
I am experiencing the same issue, and my JSDOM version is v20.0.3. |
I do see where it says it is already setup for Jest, although Jest isnt really mentioned til the last tutorial. Looking in the package.json I did not see where the tutorial was actually using jest as its test runner. It was using Craco
Looking at Craco it seems to be something specific to react, so not sure if you could use it in your application. Given that react is also a web application, craco must be doing something to make Jest run in the web instead of node. You may need to research Craco more to see what it is actually doing to allow Jest to run the way you would like it to. Im sorry I dont have any react experience. The only time I have ever used Jest is the mirage tests, but that was established before I started using the MirageJS library. I know how to run them 😄 , but not completely knowledgable in how they actually work or are configured. |
Hi, thanks for all the hard work! I've been following the guides but getting errors trying to use Mirage in Jest/StencilJS
When I invoke createServer it raises this error:
TypeError: Cannot read properties of undefined (reading 'prototype')
With the following stack trace:
The error in pretender stems from the fact that it's trying to read:
if (ctx.pretender._nativeXMLHttpRequest.prototype._passthroughCheck) {
Which is set earlier as:
this._nativeXMLHttpRequest = self.XMLHttpRequest;
And
self.XMLHttpRequest
is not defined since I'm in NodeThe text was updated successfully, but these errors were encountered: