“fetch is not found globally and no fetcher passed” when using spacejam in meteor
I'm writing unit tests to check my api. Before I merged my git
test branch with my dev branch everything was fine, but then I started to get this error:
App running at: http://localhost:4096/
spacejam: meteor is ready
spacejam: spawning phantomjs
phantomjs: Running tests at http://localhost:4096/local using test-in-console
phantomjs: Error: fetch is not found globally and no fetcher passed, to fix pass a fetch for
your environment like https://www.npmjs.com/package/unfetch.
For example:
import fetch from 'unfetch';
import { createHttpLink } from 'apollo-link-http';
const link = createHttpLink({ uri: '/graphql', fetch: fetch });
Here's a part of my api.test.js
file:
describe('GraphQL API for users', () => {
before(() => {
StubCollections.add([Meteor.users]);
StubCollections.stub();
});
after(() => {
StubCollections.restore();
});
it('should do the work', () => {
const x = 'hello';
expect(x).to.be.a('string');
});
});
The funniest thing is that I don't even have graphql
in my tests (although, I use it in my meteor
package)
Unfortunately, I didn't to find enough information (apart from apollo-link-http docs that has examples, but still puzzles me). I did try to use that example, but it didn't help and I still get the same error
javascript testing meteor graphql
add a comment |
I'm writing unit tests to check my api. Before I merged my git
test branch with my dev branch everything was fine, but then I started to get this error:
App running at: http://localhost:4096/
spacejam: meteor is ready
spacejam: spawning phantomjs
phantomjs: Running tests at http://localhost:4096/local using test-in-console
phantomjs: Error: fetch is not found globally and no fetcher passed, to fix pass a fetch for
your environment like https://www.npmjs.com/package/unfetch.
For example:
import fetch from 'unfetch';
import { createHttpLink } from 'apollo-link-http';
const link = createHttpLink({ uri: '/graphql', fetch: fetch });
Here's a part of my api.test.js
file:
describe('GraphQL API for users', () => {
before(() => {
StubCollections.add([Meteor.users]);
StubCollections.stub();
});
after(() => {
StubCollections.restore();
});
it('should do the work', () => {
const x = 'hello';
expect(x).to.be.a('string');
});
});
The funniest thing is that I don't even have graphql
in my tests (although, I use it in my meteor
package)
Unfortunately, I didn't to find enough information (apart from apollo-link-http docs that has examples, but still puzzles me). I did try to use that example, but it didn't help and I still get the same error
javascript testing meteor graphql
apollographql.com/docs/link/links/http.html#fetch
– Daniel Lizik
Feb 18 at 8:11
add a comment |
I'm writing unit tests to check my api. Before I merged my git
test branch with my dev branch everything was fine, but then I started to get this error:
App running at: http://localhost:4096/
spacejam: meteor is ready
spacejam: spawning phantomjs
phantomjs: Running tests at http://localhost:4096/local using test-in-console
phantomjs: Error: fetch is not found globally and no fetcher passed, to fix pass a fetch for
your environment like https://www.npmjs.com/package/unfetch.
For example:
import fetch from 'unfetch';
import { createHttpLink } from 'apollo-link-http';
const link = createHttpLink({ uri: '/graphql', fetch: fetch });
Here's a part of my api.test.js
file:
describe('GraphQL API for users', () => {
before(() => {
StubCollections.add([Meteor.users]);
StubCollections.stub();
});
after(() => {
StubCollections.restore();
});
it('should do the work', () => {
const x = 'hello';
expect(x).to.be.a('string');
});
});
The funniest thing is that I don't even have graphql
in my tests (although, I use it in my meteor
package)
Unfortunately, I didn't to find enough information (apart from apollo-link-http docs that has examples, but still puzzles me). I did try to use that example, but it didn't help and I still get the same error
javascript testing meteor graphql
I'm writing unit tests to check my api. Before I merged my git
test branch with my dev branch everything was fine, but then I started to get this error:
App running at: http://localhost:4096/
spacejam: meteor is ready
spacejam: spawning phantomjs
phantomjs: Running tests at http://localhost:4096/local using test-in-console
phantomjs: Error: fetch is not found globally and no fetcher passed, to fix pass a fetch for
your environment like https://www.npmjs.com/package/unfetch.
For example:
import fetch from 'unfetch';
import { createHttpLink } from 'apollo-link-http';
const link = createHttpLink({ uri: '/graphql', fetch: fetch });
Here's a part of my api.test.js
file:
describe('GraphQL API for users', () => {
before(() => {
StubCollections.add([Meteor.users]);
StubCollections.stub();
});
after(() => {
StubCollections.restore();
});
it('should do the work', () => {
const x = 'hello';
expect(x).to.be.a('string');
});
});
The funniest thing is that I don't even have graphql
in my tests (although, I use it in my meteor
package)
Unfortunately, I didn't to find enough information (apart from apollo-link-http docs that has examples, but still puzzles me). I did try to use that example, but it didn't help and I still get the same error
javascript testing meteor graphql
javascript testing meteor graphql
asked Jan 8 '18 at 16:42
Ivan PIvan P
5612919
5612919
apollographql.com/docs/link/links/http.html#fetch
– Daniel Lizik
Feb 18 at 8:11
add a comment |
apollographql.com/docs/link/links/http.html#fetch
– Daniel Lizik
Feb 18 at 8:11
apollographql.com/docs/link/links/http.html#fetch
– Daniel Lizik
Feb 18 at 8:11
apollographql.com/docs/link/links/http.html#fetch
– Daniel Lizik
Feb 18 at 8:11
add a comment |
3 Answers
3
active
oldest
votes
The problem is this: fetch
is defined when you are in the browser, and is available as fetch
, or even window.fetch
In the server it is not defined, and either needs to be imported explicity, or a polyfill like https://www.npmjs.com/package/unfetch (as suggested in the error message) needs to be imported by your test code to make the problem go away.
add a comment |
I got the same error importing a npm module doing graphql queries into my React application. The app was compiling but tests were failing since window.fetch
is not available in the Node.js runtime.
I solved the problem by installing node-fetch
https://www.npmjs.com/package/node-fetch and adding the following declarations to jest.config.js
:
const fetch = require('node-fetch')
global.fetch = fetch
global.window = global
global.Headers = fetch.Headers
global.Request = fetch.Request
global.Response = fetch.Response
global.location = { hostname: '' }
Doing so we instruct Jest on how to handle window.fetch
when it executes frontend code in the Node.js runtime.
I would love this if it worked
– Patrick Bassut
Jan 1 at 22:46
add a comment |
If you're using nodejs do the following:
Install node-fetch
npm install --save node-fetch
Add the line below to index.js
:
global.fetch = require('node-fetch');
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f48154509%2ffetch-is-not-found-globally-and-no-fetcher-passed-when-using-spacejam-in-meteo%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
The problem is this: fetch
is defined when you are in the browser, and is available as fetch
, or even window.fetch
In the server it is not defined, and either needs to be imported explicity, or a polyfill like https://www.npmjs.com/package/unfetch (as suggested in the error message) needs to be imported by your test code to make the problem go away.
add a comment |
The problem is this: fetch
is defined when you are in the browser, and is available as fetch
, or even window.fetch
In the server it is not defined, and either needs to be imported explicity, or a polyfill like https://www.npmjs.com/package/unfetch (as suggested in the error message) needs to be imported by your test code to make the problem go away.
add a comment |
The problem is this: fetch
is defined when you are in the browser, and is available as fetch
, or even window.fetch
In the server it is not defined, and either needs to be imported explicity, or a polyfill like https://www.npmjs.com/package/unfetch (as suggested in the error message) needs to be imported by your test code to make the problem go away.
The problem is this: fetch
is defined when you are in the browser, and is available as fetch
, or even window.fetch
In the server it is not defined, and either needs to be imported explicity, or a polyfill like https://www.npmjs.com/package/unfetch (as suggested in the error message) needs to be imported by your test code to make the problem go away.
answered Jan 9 '18 at 2:49
MikkelMikkel
5,54421027
5,54421027
add a comment |
add a comment |
I got the same error importing a npm module doing graphql queries into my React application. The app was compiling but tests were failing since window.fetch
is not available in the Node.js runtime.
I solved the problem by installing node-fetch
https://www.npmjs.com/package/node-fetch and adding the following declarations to jest.config.js
:
const fetch = require('node-fetch')
global.fetch = fetch
global.window = global
global.Headers = fetch.Headers
global.Request = fetch.Request
global.Response = fetch.Response
global.location = { hostname: '' }
Doing so we instruct Jest on how to handle window.fetch
when it executes frontend code in the Node.js runtime.
I would love this if it worked
– Patrick Bassut
Jan 1 at 22:46
add a comment |
I got the same error importing a npm module doing graphql queries into my React application. The app was compiling but tests were failing since window.fetch
is not available in the Node.js runtime.
I solved the problem by installing node-fetch
https://www.npmjs.com/package/node-fetch and adding the following declarations to jest.config.js
:
const fetch = require('node-fetch')
global.fetch = fetch
global.window = global
global.Headers = fetch.Headers
global.Request = fetch.Request
global.Response = fetch.Response
global.location = { hostname: '' }
Doing so we instruct Jest on how to handle window.fetch
when it executes frontend code in the Node.js runtime.
I would love this if it worked
– Patrick Bassut
Jan 1 at 22:46
add a comment |
I got the same error importing a npm module doing graphql queries into my React application. The app was compiling but tests were failing since window.fetch
is not available in the Node.js runtime.
I solved the problem by installing node-fetch
https://www.npmjs.com/package/node-fetch and adding the following declarations to jest.config.js
:
const fetch = require('node-fetch')
global.fetch = fetch
global.window = global
global.Headers = fetch.Headers
global.Request = fetch.Request
global.Response = fetch.Response
global.location = { hostname: '' }
Doing so we instruct Jest on how to handle window.fetch
when it executes frontend code in the Node.js runtime.
I got the same error importing a npm module doing graphql queries into my React application. The app was compiling but tests were failing since window.fetch
is not available in the Node.js runtime.
I solved the problem by installing node-fetch
https://www.npmjs.com/package/node-fetch and adding the following declarations to jest.config.js
:
const fetch = require('node-fetch')
global.fetch = fetch
global.window = global
global.Headers = fetch.Headers
global.Request = fetch.Request
global.Response = fetch.Response
global.location = { hostname: '' }
Doing so we instruct Jest on how to handle window.fetch
when it executes frontend code in the Node.js runtime.
const fetch = require('node-fetch')
global.fetch = fetch
global.window = global
global.Headers = fetch.Headers
global.Request = fetch.Request
global.Response = fetch.Response
global.location = { hostname: '' }
const fetch = require('node-fetch')
global.fetch = fetch
global.window = global
global.Headers = fetch.Headers
global.Request = fetch.Request
global.Response = fetch.Response
global.location = { hostname: '' }
edited Nov 24 '18 at 21:09
answered Nov 24 '18 at 14:08
RaymondMikRaymondMik
133
133
I would love this if it worked
– Patrick Bassut
Jan 1 at 22:46
add a comment |
I would love this if it worked
– Patrick Bassut
Jan 1 at 22:46
I would love this if it worked
– Patrick Bassut
Jan 1 at 22:46
I would love this if it worked
– Patrick Bassut
Jan 1 at 22:46
add a comment |
If you're using nodejs do the following:
Install node-fetch
npm install --save node-fetch
Add the line below to index.js
:
global.fetch = require('node-fetch');
add a comment |
If you're using nodejs do the following:
Install node-fetch
npm install --save node-fetch
Add the line below to index.js
:
global.fetch = require('node-fetch');
add a comment |
If you're using nodejs do the following:
Install node-fetch
npm install --save node-fetch
Add the line below to index.js
:
global.fetch = require('node-fetch');
If you're using nodejs do the following:
Install node-fetch
npm install --save node-fetch
Add the line below to index.js
:
global.fetch = require('node-fetch');
answered Jan 31 at 1:10
BradBrad
6,62383461
6,62383461
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f48154509%2ffetch-is-not-found-globally-and-no-fetcher-passed-when-using-spacejam-in-meteo%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
apollographql.com/docs/link/links/http.html#fetch
– Daniel Lizik
Feb 18 at 8:11