我正在使用 Angular 9 并在深入研究后将 angular 的默认单元测试替换为旁观者和开玩笑,这很有趣,而且我几乎没有可以正常工作的测试,但是在尝试测试某些父组件时突然出现了这个问题,导致了丑陋的错误(看问题标题)我不知道如何解决,很高兴得到一些帮助,代码如下
其他类似的测试正在工作,但是即使我删除了模板的所有标记并只写了愚蠢的 div,并且取消了对测试的模拟,我仍然得到这个无赖...尝试重新启动服务器没有帮助。
规格
import { Spectator, createComponentFactory } from '@ngneat/spectator/jest';
import { PlannerScreenComponent } from './planner-screen.component';
import { SlotsListComponent } from '../planner/components/slots-list/slots-list.component';
import { MockComponent } from 'ng-mocks';
describe('PlannerScreenComponent suit', () => {
let spectator: Spectator<PlannerScreenComponent>;
const createComponent: () => Spectator<PlannerScreenComponent> = createComponentFactory({
component: PlannerScreenComponent,
declarations: [MockComponent(SlotsListComponent)]
});
beforeEach(() => (spectator = createComponent()));
it('should create plannerScreenComponent ', () => {
const plannerScreenComponent = spectator.component;
expect(plannerScreenComponent).toBeTruthy();
});
});
组件.ts
import { Component, OnInit, Input } from '@angular/core';
@Component({
selector: 'planner-screen',
templateUrl: './planner-screen.component.html',
styleUrls: ['./planner-screen.component.scss']
})
export class PlannerScreenComponent implements OnInit {
@Input() isSplittedScreen = false;
constructor() {}
ngOnInit() {}
}
组件.html
section [class.splitted-screen]="isSplittedScreen" class="planner-screen-wrapper">
<aside class="left-ruller-container"></aside>
<div class="top-middle-title">
<div>title</div>
</div>
<div class="main-panel-container">
<slots-list></slots-list>
</div>
<aside class="right-ruller-container"></aside>
</section>