Skip to content
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

[Regression v8.3.0] Incorrect error: Adding route with same name or matcher as existing route. #493

Closed
gr2m opened this issue Jan 2, 2020 · 2 comments · Fixed by #494
Closed

Comments

@gr2m
Copy link

gr2m commented Jan 2, 2020

Minimal test case

const fetchMock = require("fetch-mock");

function matcher1() {
  return true;
}

function matcher2() {
  return true;
}

const response = {
  ok: true
};

const mock = fetchMock
  .sandbox()
  .postOnce(matcher1, response)
  .postOnce(matcher2, response);

test();

async function test() {
  await mock("https://example.com", { method: "POST" });
  await mock("https://example.com", { method: "POST" });

  console.assert(mock.done(), "mock.done() returns true");
  console.log("done.");
}

In fetch-mock v8.2.1, it just logs done..

When running the same code in v8.3.0, it throws the following error

[project path]/node_modules/fetch-mock/cjs/lib/set-up-and-tear-down.js:41
                throw new Error(
                ^

Error: fetch-mock: Adding route with same name or matcher as existing route. See `overwriteRoutes` option.
    at Function.FetchMock.addRoute (/Users/gregor/Projects/octokit/auth-app.js/node_modules/fetch-mock/cjs/lib/set-up-and-tear-down.js:41:9)
    at Function.FetchMock.mock (/Users/gregor/Projects/octokit/auth-app.js/node_modules/fetch-mock/cjs/lib/set-up-and-tear-down.js:6:8)
    at Function.FetchMock.(anonymous function) [as once] (/Users/gregor/Projects/octokit/auth-app.js/node_modules/fetch-mock/cjs/lib/set-up-and-tear-down.js:78:32)
    at Function.FetchMock.(anonymous function) [as postOnce] (/Users/gregor/Projects/octokit/auth-app.js/node_modules/fetch-mock/cjs/lib/set-up-and-tear-down.js:78:32)
    at Object.<anonymous> (/Users/gregor/Projects/octokit/auth-app.js/gregor.js:18:4)
    at Module._compile (internal/modules/cjs/loader.js:778:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
    at Module.load (internal/modules/cjs/loader.js:653:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
    at Function.Module._load (internal/modules/cjs/loader.js:585:3)
@wheresrhys
Copy link
Owner

Thanks for the bug report. Fix on its way.

@wheresrhys
Copy link
Owner

fixed in 8.3.1

jeremymeng added a commit to jeremymeng/azure-sdk-for-js that referenced this issue Jan 28, 2020
Resolves Azure#6714

There was a regression in fetch-mock

wheresrhys/fetch-mock#493

which is already fixed in the latest version of fetch-mock.
jeremymeng added a commit to Azure/azure-sdk-for-js that referenced this issue Jan 28, 2020
)

* [core-http][test] revert workaround of pinning fetch-mock version

Resolves #6714

There was a regression in fetch-mock

wheresrhys/fetch-mock#493

which is already fixed in the latest version of fetch-mock.

* Update pnpm-lock.yaml
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants