【发布时间】:2017-03-08 21:35:26
【问题描述】:
对于我们目前使用带有 angular2 的原生脚本启动的项目,单元测试对我们来说是必不可少的。所以我首先尝试为给定的杂货示例实现一些简单的,只是为了掌握它。非常简单的测试,例如测试电子邮件地址的验证是否正常工作并且实施起来并不多。 一旦我开始进行更复杂的测试,我只会在涉及到 Testbed 时出现错误。
这是我使用 Testbed 实现的最简单的凝视实现:
import "reflect-metadata";
import 'nativescript-angular/zone.js/dist/zone-nativescript';
import {TestBed} from '@angular/core/testing';
import { UserService } from "../../../shared/user/user.service";
declare var describe: any;
declare var expect: any;
declare var it: any;
declare var beforeEach: any;
describe('UserService', () => {
beforeEach(() => {
TestBed.configureTestingModule({
providers: [UserService]
});
});
it("just testing", () => {
console.log('hier');
expect(false).toBe(false);
});
});
这是我一运行就遇到的错误:
sampleGroceries[66839]: CONSOLE LOG file:///app/tests/shared/user/user.service.spec.js:13:20: hier
NativeScript / 10.0 (10.0; iPhone) A suite contains spec with an expectation FAILED
TypeError: undefined is not an object (evaluating 'ProxyZoneSpec.assertPresent') in file:///app/tns_modules/@angular/core/testing/../bundles/core-testing.umd.js (line 385)
resetFakeAsyncZone@file:///app/tns_modules/@angular/core/testing/../bundles/core-testing.umd.js:385:22
file:///app/tns_modules/@angular/core/testing/../bundles/core-testing.umd.js:1255:31
attemptSync
run
execute
queueRunnerFactory
execute
fn
attemptAsync
run
execute
queueRunnerFactory
fn
attemptAsync
run
execute
queueRunnerFactory
execute
execute
runTests@file:///app/tns_modules/nativescript-unit-test-runner/main-view-model.js:216:23
file:///app/tns_modules/nativescript-unit-test-runner/main-view-model.js:187:101
tick@file:///app/tns_modules/timer/timer.js:17:26
UIApplicationMain@[native code]
start@file:///app/tns_modules/application/application.js:234:26
anonymous@file:///app/./tns_modules/nativescript-unit-test-runner/app.js:3:18
evaluate@[native code]
moduleEvaluation@[native code]
[native code]
promiseReactionJob@[native code]
NativeScript / 10.0 (10.0; iPhone) UserService just testing FAILED
TypeError: undefined is not an object (evaluating 'ProxyZoneSpec.assertPresent') in file:///app/tns_modules/@angular/core/testing/../bundles/core-testing.umd.js (line 385)
resetFakeAsyncZone@file:///app/tns_modules/@angular/core/testing/../bundles/core-testing.umd.js:385:22
file:///app/tns_modules/@angular/core/testing/../bundles/core-testing.umd.js:1255:31
attemptSync
run
execute
queueRunnerFactory
execute
fn
attemptAsync
run
execute
queueRunnerFactory
fn
attemptAsync
run
onComplete
clearStack
run
complete
clearStack
run
execute
queueRunnerFactory
execute
fn
attemptAsync
run
execute
queueRunnerFactory
fn
attemptAsync
run
execute
queueRunnerFactory
execute
execute
runTests@file:///app/tns_modules/nativescript-unit-test-runner/main-view-model.js:216:23
file:///app/tns_modules/nativescript-unit-test-runner/main-view-model.js:187:101
tick@file:///app/tns_modules/timer/timer.js:17:26
UIApplicationMain@[native code]
start@file:///app/tns_modules/application/application.js:234:26
anonymous@file:///app/./tns_modules/nativescript-unit-test-runner/app.js:3:18
evaluate@[native code]
moduleEvaluation@[native code]
[native code]
promiseReactionJob@[native code]
NativeScript / 10.0 (10.0; iPhone): Executed 2 of 2 (2 FAILED) ERROR (0.02 secs / 0.002 secs)
我尝试了各种方法,例如 import zone.js/dist/proxy.js 和许多其他方法,但均未成功。
有人知道我错过了什么吗?您如何正确实现它,以便单元测试适用于带有测试平台的本机脚本???
【问题讨论】:
-
我也遇到了这个错误。有人有解决方案吗?
标签: unit-testing jasmine nativescript angular2-nativescript