"Error: Nock: No match for request" How to quickly understand what doesn't match?

I often face this error (Error: Nock: No match for request) using Nock, but I find it hard to quickly understand what doesn’t match in order to adjust.

I used to use nock(apiUrl).persist().log(console.log)(link) that was doing the job pretty well. But it’s been deprecated and I’ve recently updated the dependancy. Therefore I need to adapt, yet I find it hard to grasp what info is interesting for my debugging.

How to get something similar to Jest, obviously comparing what was expected, and what was actually called for quick and straightforward debugging ?

4 thoughts on “"Error: Nock: No match for request" How to quickly understand what doesn't match?”

  1. For those that might help, here is how you must read the error :

      console.log src/repositories/repository.js:137
        Error: Nock: No match for request {
          "method": "PATCH",
          "url": "http://random.example.ci.indb:8080/v1/subscriptions?user_id=c141db67-2e85-46e4-b07e-95d2e913e05d",
          "headers": {
            "accept": "application/json, text/plain, */*",
            "content-type": "application/json;charset=utf-8",
            "x-forwarded-proto": "https",
            "jwt": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJtam9sbG5pci50ZXN0LmluZGIiLCJzdWIiOiI3MzIyNDJiNy03YmUxLTRmOWItYjY3MC1jNGVkZmNhZTExMzIiLCJzdWJsaXZlIjo0MiwiaWF0IjoxNjE0NjMyMDY2LCJleHAiOjE2MTcyMjQwNjZ9.yS58zjEYj4Yx4iSga0w-NFA1QbdznD1vLGAUhEcjyXo",
            "user-agent": "axios/0.21.1",
            "content-length": 146
          },
          "body": "{\"user_id\":\"c141db67-2e85-46e4-b07e-95d2e913e05d\",\"conditions_accepted_date\":\"Mon Mar 01 2021 21:14:22 GMT+0100 (Central European Standard Time)\"}"
        }
    

    The error print into the console what your code is actually calling. You need to compare those parameters thoroughly with what you’ve given in your test’s Nock mock. In my case it was due to a mismatch with the date input.

    The other infos seems useless.

    Reply

Leave a Comment