“未在全局范围内找到提取并且未通过提取器"在流星中使用 spacejam 时 [英] "fetch is not found globally and no fetcher passed" when using spacejam in meteor
问题描述
我正在编写单元测试来检查我的 api.在我将 git
test 分支与我的 dev 分支合并之前,一切都很好,但后来我开始遇到这个错误:
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 });
这是我的 api.test.js
文件的一部分:
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');
});
});
最有趣的是我的测试中甚至没有 graphql
(尽管我在我的 meteor
包中使用了它)不幸的是,我没有找到足够的信息(除了 apollo-link-http docs 有例子,但仍然让我困惑).我确实尝试使用该示例,但它没有帮助,我仍然遇到相同的错误
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
推荐答案
如果您使用 nodejs,请执行以下操作:
If you're using nodejs do the following:
安装node-fetch
npm install --save node-fetch
将以下行添加到 index.js
:
global.fetch = require('node-fetch');
这篇关于“未在全局范围内找到提取并且未通过提取器"在流星中使用 spacejam 时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!