trayio / mock-inspect

Mocks network requests and allows you to make assertions about how these requests happened. Supports auto-mocking of graphQL requests given a valid schema.
MIT License
18 stars 1 forks source link

Add an example file and test for using mock-inspect with nodejs #73

Closed aychtang closed 3 years ago

aychtang commented 3 years ago

Hey guys, was looking at potentially adding some examples like I mentioned in #17.

There is an error with the example test I added:

 FAIL  examples/nodejs/nodeJsExample.spec.ts
  ● should send a request to https://example.com

    Unhandled error. (Error: [MSW] Error: captured a GET https://example.com/ request without a corresponding request handler.

      If you wish to intercept this request, consider creating a request handler for it:

      rest.get('https://example.com/', (req, res, ctx) => {
        return res(ctx.text('body'))
      })

      at onUnhandledRequest (node_modules/msw/node/index.js:2081:19)
      at Object.<anonymous> (node_modules/msw/node/index.js:2155:25)

but I'm not sure why this occurs. I don't really know about MSW but maybe I'm misusing mock-inspect in this case?

aychtang commented 3 years ago

It doesn't seem to correctly mock the call in examples/nodejs/index.ts

aychtang commented 3 years ago

Ok fixed it in d79931d101ebb02542a70cb39c8d73e7634be439, it's just that in the mocked request I was including www. in the requestPattern.

The github action is failing as the new test is not under rootDir which is currently /src, where do we want to put this stuff? I think it shouldn't be in /src as it's not source code for the app.

thomaschaplin commented 3 years ago

@aychtang what's the status of this PR? Looks like the unit test pipeline is failing

aychtang commented 3 years ago

I will add some kind of example as a separate repo which we can then link to from the README of the main project.