角度测试得到



如何在角度中测试?

get isPerson() {
return this.persons.some((person) => person === this.personId);
}

我尝试过这样的东西,但没有成功:

it('should get person', () => {
const person = new Person('John', 'Doe');
const spy = spyOnProperty(person, 'isPerson').and.returnValue(
'john doe'
);
expect(person.fullName).toBe('john doe');
expect(spy).toHaveBeenCalled();
});

如果您正在测试组件,请执行以下

it('should get person', () => {
const person = new Person('John', 'Doe');
component.person = person
component.personId = 'John'
fixture.detectChanges()

expect(component.isPerson).toBeTruthy() 
});

最新更新