I have the following component class in angular (v15):
export class MyComponent implements OnInit {
mobileMode: boolean = false;
constructor(private breakPointObserver: BreakpointObserver) {
}
ngOnInit() {
this.breakPointObserver.observe([Breakpoints.XSmall])
.subscribe((state: BreakpointState) => {
this.mobileMode = state.matches;
});
}
}
I'm trying and failing to write a unit test to test that mobileMode is set to true when the screen size is extra small. This is my test:
it('should set mobileMode to true when screen is extra small', () => {
spyOnProperty(window, 'innerWidth').and.returnValue(500);
window.dispatchEvent(new Event('resize'));
fixture.detectChanges();
expect(component.mobileMode).toBeTrue();
});
My test result is just: Expected false to be true
How I can test this?
I'm also tried outerWidth.
I'm on Version 15 of Angular/ Angular CLI and node 18.12