【发布时间】:2016-04-28 13:03:18
【问题描述】:
所以我正在使用 Gulp、Gulp-Jasmine 和 SystemJS 来测试 Angular2 演示应用程序。真的很简单。我已经设法让 System.config 块工作并加载规范文件,但是在尝试运行 beforeEach 块时它会崩溃并出现以下错误...
{ [错误:TypeError:_global.beforeEach 不是函数 在 Object.eval (D:/ng2demo/node_modules/angular2/src/testing/matcher s.js:26:9) 在 eval (D:/ng2demo/node_modules/angular2/src/testing/matchers.js:20 5:4) 在 eval (D:/ng2demo/node_modules/angular2/src/testing/matchers.js:20 6:3) 在评估(本机) 在 Object.eval (D:/ng2demo/node_modules/angular2/src/testing/testing .js:10:18) 在 eval (D:/ng2demo/node_modules/angular2/src/testing/testing.js:245 :4) 在 eval (D:/ng2demo/node_modules/angular2/src/testing/testing.js:246 :3) 在评估(本机) 评估 D:/ng2demo/node_modules/angular2/src/testing/matchers.js 评估 D:/ng2demo/node_modules/angular2/src/testing/testing.js 评估 D:/ng2demo/node_modules/angular2/testing.js 加载 D:/ng2demo/app/assets/services/config.service.spec.js 时出错] originalErr: [TypeError: _global.beforeEach 不是函数] }
我的 gulp 任务概述如下...
var gulp = require('gulp');
var jasmine = require('gulp-jasmine');
var System = require('systemjs');
gulp.task('newtest', () => {
System.config({
baseURL: "",
transpiler: 'typescript',
defaultJSExtensions: true,
packages: {
app: {
format: 'register',
defaultExtension: 'js'
},
},
map:{
'angular2':'node_modules/angular2',
'rxjs':'node_modules/rxjs',
},
});
Promise.all([
System.import('app/assets/services/config.service.spec'),
]).then(function(){
gulp.src(['app/assets/services/config.service.spec'])
.pipe(jasmine())
}).catch(console.error.bind(console));
});
我的规范文件看起来像这样...
/// <reference path="../../../typings/browser/ambient/systemjs/index.d.ts"/>
/// <reference path="../../../typings/browser/ambient/jasmine/index.d.ts"/>
import {Injector, provide} from "angular2/core";
import {Http, BaseRequestOptions, Response, ResponseOptions} from "angular2/http";
import {MockBackend} from "angular2/http/testing";
import {ConfigService} from "./config.service";
import {it, describe, beforeEach, inject, expect} from "angular2/testing";
describe("ConfigService", () => {
// THIS IS THE LINE THAT FAILS !!!
beforeEach(() => {
//Do some prep
});
it("it does a test and evals to true", () => {
expect(true).toBe(true);
});
});
- 我做错了什么,我该如何克服这个错误???
- 我需要规范顶部的参考路径还是有更好的方法?
【问题讨论】:
-
我认为这不是您的实际代码,对吧?你已经用 //Do some prep comment 注释掉了右括号和括号
-
根据评论编辑了上面的内容,还是不行!!!
标签: typescript angular gulp jasmine systemjs