{"action":"closed","issue":{"url":"https://api.github.com/repos/wheresrhys/fetch-mock/issues/46","labels_url":"https://api.github.com/repos/wheresrhys/fetch-mock/issues/46/labels{/name}","comments_url":"https://api.github.com/repos/wheresrhys/fetch-mock/issues/46/comments","events_url":"https://api.github.com/repos/wheresrhys/fetch-mock/issues/46/events","html_url":"https://github.com/wheresrhys/fetch-mock/issues/46","id":123628295,"number":46,"title":"Cannot mock relative URLs in v3.0.4","user":{"login":"jwarby","id":617098,"avatar_url":"https://avatars.githubusercontent.com/u/617098?v=3","gravatar_id":"","url":"https://api.github.com/users/jwarby","html_url":"https://github.com/jwarby","followers_url":"https://api.github.com/users/jwarby/followers","following_url":"https://api.github.com/users/jwarby/following{/other_user}","gists_url":"https://api.github.com/users/jwarby/gists{/gist_id}","starred_url":"https://api.github.com/users/jwarby/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jwarby/subscriptions","organizations_url":"https://api.github.com/users/jwarby/orgs","repos_url":"https://api.github.com/users/jwarby/repos","events_url":"https://api.github.com/users/jwarby/events{/privacy}","received_events_url":"https://api.github.com/users/jwarby/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-12-23T09:35:44Z","updated_at":"2015-12-24T16:17:35Z","closed_at":"2015-12-24T16:17:35Z","body":"As of v3.0.4, mocking a relative URL results in an `Error` being thrown from the dependency module [`node-fetch`](https://github.com/bitinn/node-fetch):\r\n\r\n```\r\nError: only absolute urls are supported\r\n    at new Request (node_modules/fetch-mock/node_modules/node-fetch/lib/request.js:34:9)\r\n    at toRequest (node_modules/fetch-mock/src/fetch-mock.js:65:13)\r\n    at Object.route.matcher (node_modules/fetch-mock/src/fetch-mock.js:111:15)\r\n    at node_modules/fetch-mock/src/fetch-mock.js:233:15\r\n    at Array.some (native)\r\n    at routes.forEach.routes.forEach.routes.some (node_modules/fetch-mock/src/fetch-mock.js:231:11)\r\n    at mock (node_modules/fetch-mock/src/fetch-mock.js:329:21)\r\n    ....\r\n```\r\n\r\nIn my use case, I am writing tests for a Redux application which uses `fetch` to grab some i18n data defined in a JSON file.   The code I am testing looks like this:\r\n\r\n```javascript\r\nfetch(`public/i18n/${locale}.json`)\r\n  .then(/* ...snip... */)\r\n```\r\n\r\nThe tests are written in [`mocha`](https://mochajs.org/) and are executed through Node.js, so I use [`isomorphic-fetch`](https://github.com/matthew-andrews/isomorphic-fetch) assigned to the `global` object inside the test, to fill in for the browser's `fetch` function, and use `fetch-mock` to mock the response:\r\n\r\n```javascript\r\nimport fetchMock from 'fetch-mock'\r\nimport fetch from 'isomorphic-fetch'\r\n\r\nglobal.fetch = fetch\r\n/* ...snip... */\r\nfetchMock.mock(`public/i18n/${locale}.json`, { /* fixture i18n data */ })\r\n```\r\n\r\nThis code worked fine in v3.0.3 as `fetch-mock` wasn't using `Request` from `node-fetch`, which sets the absolute URL limitation ([LIMITS.md in `node-fetch` repository](https://github.com/bitinn/node-fetch/blob/master/LIMITS.md)).\r\n\r\nRelated issue in `node-fetch`: https://github.com/bitinn/node-fetch/issues/43\r\n"}}