最新消息: 电脑我帮您提供丰富的电脑知识,编程学习,软件下载,win7系统下载。

未捕获的ReferenceError:未定义必需

IT培训 admin 3浏览 0评论

未捕获的ReferenceError:未定义必需

我是jasmine-karma测试的新手,并且遇到了一些配置问题。我已经完成了一些教程,到目前为止我已经创建了package.json,karma.conf.js和gulpfile.js。

当我尝试运行测试时,它会打开chrome并且karma开始运行。但它给出了如下错误;

这是我的gulpfile.js文件

'use strict'
var gulp = require('gulp');
var Server = require('karma').Server;


//Run test once and exit
gulp.task('test', function (done){
    new Server(
        {
            configFile: __dirname + '/karma.conf.js',
            singleRun: false
        }, done).start();
});

// Watch for file changes and re-run tests on each change
gulp.task('tdd', function (done) {
    new Server({
        configFile: __dirname + '/karma.conf.js'
    }, done).start();
});

gulp.task('default', ['tdd']);
回答如下:

看起来你正在尝试为服务器端代码运行客户端测试(例如你的gulpfile)。

Node.js在V8引擎上运行,该引擎也被谷歌使用,但是具有包含不同属性的不同全局对象。

在浏览器中,标准全局对象是“窗口”,例如包含“文档”属性。因此,documentwindow.documentthis.document都是一样的。

虽然如果您尝试在节点js环境中使用“document”,您将得到相同的类型错误。

底线 - 谷歌浏览器不知道'需要'是什么,因为它不是全局“窗口”对象中的属性。

未捕获的ReferenceError:未定义必需

我是jasmine-karma测试的新手,并且遇到了一些配置问题。我已经完成了一些教程,到目前为止我已经创建了package.json,karma.conf.js和gulpfile.js。

当我尝试运行测试时,它会打开chrome并且karma开始运行。但它给出了如下错误;

这是我的gulpfile.js文件

'use strict'
var gulp = require('gulp');
var Server = require('karma').Server;


//Run test once and exit
gulp.task('test', function (done){
    new Server(
        {
            configFile: __dirname + '/karma.conf.js',
            singleRun: false
        }, done).start();
});

// Watch for file changes and re-run tests on each change
gulp.task('tdd', function (done) {
    new Server({
        configFile: __dirname + '/karma.conf.js'
    }, done).start();
});

gulp.task('default', ['tdd']);
回答如下:

看起来你正在尝试为服务器端代码运行客户端测试(例如你的gulpfile)。

Node.js在V8引擎上运行,该引擎也被谷歌使用,但是具有包含不同属性的不同全局对象。

在浏览器中,标准全局对象是“窗口”,例如包含“文档”属性。因此,documentwindow.documentthis.document都是一样的。

虽然如果您尝试在节点js环境中使用“document”,您将得到相同的类型错误。

底线 - 谷歌浏览器不知道'需要'是什么,因为它不是全局“窗口”对象中的属性。

发布评论

评论列表 (0)

  1. 暂无评论