question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

supertest along with msw for mocks

See original GitHub issue

Environment

Name Version
msw 0.19.5
node 14.x
OS ubuntu
node-request-interceptor@0.2.6

Request handlers

setupServer(
    rest.post(process.env.ai_api_endpoint + '/datasync/job-profile/', (req, res, ctx) => {

        /**
         * here need to check actual response of ai api. 
         * but i think its just empty
         */
        return res(ctx.status(200), ctx.json({}))
    }),
)



await request(app)
            .post("/user/login")
            .set("Accept", "application/json")
            .send({
                "email": user.email,
                "password": "123"
            })


using msw with supertest causes empty post i.e data sent in “/user/login” is always empty. if i comment out the msw server, post json is not empty anymore

same problem as this https://github.com/mswjs/msw/issues/209#issuecomment-654427646

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:9 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
manishiitgcommented, Jul 14, 2020

i can confirm the issues is fixed. it works for me now. thanks @kettanaito

1reaction
kettanaitocommented, Jul 14, 2020

The issue has been fixed in node-request-interceptor 0.3.2. The update on the msw side will follow and be released in 0.20.0.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Mock Service Worker adopts a brand-new request interception ...
The new algorithm is an internal change, so there are no breaking changes to the public API or behaviors of MSW in Node.js....
Read more >
MSW logging warnings for unhandled Supertest requests
The request GET http://127.0.0.1:55984/api is one that Supertest is making to the app, which is the whole point of the test, not one...
Read more >
Comparison with other tools - Mirage JS
MSW is a mocking library that can run in the browser or node. ... Mirage was built for testing and brings along concepts...
Read more >
Node - Getting Started - Mock Service Worker Docs
One of the most common usages of Mock Service Worker in Node is utilizing our request handlers for integration tests. We are going...
Read more >
React Testing Library - Mock Service Worker (msw) - YouTube
A tutorial on how to mock API calls with Mock Service Worker ( msw ) for writing tests. I'm using React Testing Library...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found