gpt4 book ai didi

javascript - Natviescript 中的 Angular 单元测试 : reflect-metadata shim is required when using class decorators

转载 作者:行者123 更新时间:2023-11-28 05:53:40 25 4
gpt4 key购买 nike

有人可以帮助我解决单元测试问题吗?我正在尝试使用 Angular2 进行测试,因此我有以下 tests/example.ts 文件:

import {beforeEachProviders, inject} from "@angular/core/testing";
import {CloudService} from "../Shared/Cloud/cloud.service";
import {Login} from "../Components/Dock/Login/login.component";

describe('1st tests', () => {
it('true is true', () => expect(true).toEqual(true));
});

describe('Login Component', () => {
var _cloudService = new CloudService;
var login = new Login(_cloudService);
beforeEachProviders(() => [CloudService]);

it("Toggles Child Opacity on Click", function() {
expect(login.google.nativeElement.style.opacity.toEqual(0)); //Check if the counter equals 42.
});
});

如果我只有第一个测试,一切都运行良好,但在第二个测试(Angular 测试)中,我得到以下输出:

JS: NSUTR: successfully connected to karma

17 06 2016 13:39:52.033:INFO [NativeScript / 23 (6.0; Google Nexus 6 - 6.0.0 - API 23 - 1440x2560)]: Connected on socket /#RVDKwphYh_vDt9dxAAAA with id NativeScriptUnit-6168

JS: NSUTR: downloading http://192.168.101.2:9876/context.json

JS: NSUTR: disregarding second execution

JS: NSUTR: eval script /base/node_modules/jasmine-core/lib/jasmine-core/jasmine.js?391e45351df9ee35392d2e5cb623221a969fc009

JS: NSUTR: eval script /base/node_modules/karma-jasmine/lib/boot.js?945a38bf4e45ad2770eb94868231905a04a0bd3e

JS: NSUTR: eval script /base/node_modules/karma-jasmine/lib/adapter.js?7975a273517f1eb29d7bd018790fd4c7b9a485d5

JS: NSUTR: require script /base/app/tests/example.js?a455c4e9fa5e9b056e0c931845325f514b63be7f from ../../tests/example.js

JS: NSUTR: this.error: reflect-metadata shim is required when using class decorators

JS: at ../../tests/example.js 17 06 2016 13:39:53.605:WARN [NativeScript / 23 (6.0; Google Nexus 6 - 6.0.0 - API 23 - 1440x2560)]: Adapter did not report total number of specs. NativeScript / 23 (6.0; Google Nexus 6 - 6.0.0 - API 23 - 1440x2560): Executed 0 of 0 SUCCESS (0 secs / 0 secs)

NativeScript / 23 (6.0; Google Nexus 6 - 6.0.0 - API 23 - 1440x2560) ../../tests/example.js at line 0 FAILED reflect-metadata shim is required when using class decorators NativeScript / 23 (6.0; Google Nexus 6 - 6.0.0 - API 23 - 1440x2560):

Executed 1 of 0 (1 FAILED) ERROR (0.114 secs / 0 secs)

JS: NSUTR: completeAck

JS: NSUTR-socket.io: io server disconnect

如果我将行 import "reflect-metadata"; 添加到文件中,我会得到相同的结果...

你知道我做错了什么吗?

最佳答案

这已经很旧了,但我想我应该发表评论,以防其他人偶然发现这个问题。

我一直遇到这个问题,它让我发疯。我找到了一种解决方法,将转译的 Javascript 文件模式添加到我的 karma.config 中。我还必须从 karma.config 中删除 Typescript 文件模式。这不是我所希望的,但对于其他寻求此问题答案的人来说,这是一种解决方法。

关于javascript - Natviescript 中的 Angular 单元测试 : reflect-metadata shim is required when using class decorators,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37882448/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com