Git Product home page Git Product logo

Comments (7)

snaptopixel avatar snaptopixel commented on May 23, 2024 1

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?

from miragejs.

nemonemi avatar nemonemi commented on May 23, 2024 1

I am experiencing the same issue, and my JSDOM version is v20.0.3.
My application was set up a year ago and hasn't been touched, except for the miragejs version being updated by the bot.

from miragejs.

cah-brian-gantzler avatar cah-brian-gantzler commented on May 23, 2024 1

@cah-brian-gantzler sorry for the delay in responding, the tutorial walks through using it with Jest: https://miragejs.com/tutorial/part-9/

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

 "scripts": {
    "start": "craco start",
    "start:final": "REACT_APP_DEMO=true yarn start",
    "build": "craco build",
    "test": "craco test",
    "eject": "react-scripts eject"
  },

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.

from miragejs.

cah-brian-gantzler avatar cah-brian-gantzler commented on May 23, 2024

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 mirage-msw. This is experimental at this time. Pretender will still be included in your builds, as it has not yet been removed from miragejs and made an optional dependency.

If you would like to user mirage-msw add it to your package.json, then in your server import and add the following (talked about in this issue #1013). Would be interested in any feedback to eventually get this to be part of MirageJS proper.

import { Server } from 'miragejs';
import MswInterceptor from 'mirage-msw';

new Server({
   // your config options
   interceptor: new MswInterceptor(),
});

from miragejs.

cah-brian-gantzler avatar cah-brian-gantzler commented on May 23, 2024

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.

from miragejs.

snaptopixel avatar snaptopixel commented on May 23, 2024

@cah-brian-gantzler sorry for the delay in responding, the tutorial walks through using it with Jest:
https://miragejs.com/tutorial/part-9/

from miragejs.

IanVS avatar IanVS commented on May 23, 2024

@snaptopixel Are you using jsdom, if so, what version?

from miragejs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.