I'm trying to test this function here :
ngOnChanges(): void {
if (this.isCustomer) {
let sectionCopy = [...this.sections];
this.sectionsNotFilled = sectionCopy.find(section => section.filled === false);
...
}
}
I saw on a lot of ressource that in order to trigger ngOnChanges, I have to use fixture.detectChanges();, but i still can not test and got the wrong result on my test:
...
let component: XXX;
let fixture: ComponentFixture<XXX>;
...
const sections = [
{
key: 'SECTION1',
name: 'Section 1',
filled: true
},
{
key: 'SECTION2',
name: 'Section 2',
filled: false
}
];
...
it('should do test', () => {
const sectionsMock = {...sections};
component.sections = sectionsMock;
component.isCustomer = true;
console.log(component.sections); => section are here
//trigger
fixture.detectChanges();
console.log(component.sectionsNotFilled);
expect(component.sectionsNotFilled).toBe(true); => return false :/
});
Any ideas? Did I did something wrong?