测试子组件时出现如下错误:
1. If 'app-user' is an Angular component and it has 'InwelcomeMsg' input, then verify that it is part of this module.
在测试组件时。我正在使用testing-library
angular with jestjs
。无法弄清楚这个问题。
容器组件.ts:
import { Component, OnInit, Output } from '@angular/core';
@Component({
selector: 'app-shell-user',
templateUrl: './shell-user.component.html',
styleUrls: ['./shell-user.component.scss']
})
export class ShellUserComponent implements OnInit {
@Output() OutwellcomeMsg: string | undefined;
title = "Welcome to user!!"
constructor() { }
ngOnInit(): void {
this.OutwellcomeMsg = this.title;
}
}
html:
<section>
<app-user [InwelcomeMsg]="OutwellcomeMsg"></app-user>
</section>
子组件.ts:
import { Component, Input, OnInit } from '@angular/core';
@Component({
selector: 'app-user',
templateUrl: './user.component.html',
styleUrls: ['./user.component.scss']
})
export class UserComponent implements OnInit {
@Input()
InwelcomeMsg!: string | undefined;
constructor() { }
ngOnInit(): void { }
}
child.test.spec:
import { render, screen } from '@testing-library/angular';
import { UserComponent } from './user.component';
describe('UserComponent', () => {
it('should find the paragrap text "Hi Adil"', async () => {
await render(UserComponent, {
declarations: [],
componentProperties: {
InwelcomeMsg: "Hi Adil"
} as any
});
expect(await screen.findByText(/Hi Adil/i)).toBeTruthy();
});
});
不知道我在测试中想念她什么。有人帮我吗?