一般的に角度/テストの新機能です。テストに関するAngularドキュメンテーションを通して作業しており、私は苦労しています。このサイトで回答を検索しましたが、失敗しました。また、app.module.ts
ファイルに追加のインポートを追加しようとしました。 Error: Unexpected value 'VoteComponent' declared by the module 'DynamicTestModule'
予期しない値 'DynamicTestModule'モジュールによって 'VoteComponent'が宣言されました
component.tsファイルは非常に基本的なものです::
export class VoteComponent {
totalVotes = 0;
upVote() {
this.totalVotes++;
}
downVote() {
this.totalVotes--;
}
}
spec.tsファイル:このエラーを受け、ジャスミンを使用して
(私はdownVote()
のコードを書いていない)
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { VoteComponent } from './vote.component';
describe ('VoteComponent',() => {
let comp: VoteComponent;
beforeEach(() => {
TestBed.configureTestingModule({
declarations: [VoteComponent],
});
const fixture = TestBed.createComponent(VoteComponent);
comp = fixture.componentInstance;
});
it('should increment total votes when upvoted',() => {
comp.upVote();
expect(comp.totalVotes).toBe(1);
});
});
ご協力いただければ幸いです。ありがとうございました。
あなたは '@ Component'メタデータコンポーネントに追加しましたか? – yurzui
いいえ、上に書かれているのは、すべてcomponent.tsファイルに書かれています。 – Myster1o619
あなたはそれをしなければなりません – yurzui