错误:<spyon>:PhantomJS中不存在fetch()方法

时间:2018-03-02 10:38:54

标签: testing webpack phantomjs karma-jasmine

我正在使用PhantomJS来运行测试。

并收到以下错误:

  

错误:: fetch()方法不存在

这是karma.config.js文件:

var webpackConfig = require('./webpack.config.js');

    module.exports = config => {
      config.set({
        basePath: '',
        frameworks: ['jasmine'],
        files: ['node_modules/babel-polyfill/dist/polyfill.js','./src/components/**/*.spec.ts'],
        preprocessors: {
          './src/components/**/*.spec.ts': ['webpack']
        },
        mime: {
          'text/x-typescript': ['ts', 'tsx']
        },
        webpack: webpackConfig,
        reporters: ['progress'],
        port: 9876,
        colors: true,
        logLevel: config.LOG_INFO,
        autoWatch: true,
        browsers: ['PhantomJS'],
        singleRun: false,
        webpackMiddleware: {
          noInfo: true
        },
        concurrency: Infinity
      });
    };

1 个答案:

答案 0 :(得分:1)

尝试将whatwg-fetch polyfill添加到您的karma.config.js

files: [
      'node_modules/whatwg-fetch/fetch.js',
      ...
    ]