Currently, I am in the process of learning Jasmine and I have encountered an issue that I need some help with. During my test case run, specifically on the line
expect(component.roleModal.visible).toBeTrue();
, I am receiving an error message stating Expected false to be true
.
describe('ManageRolesComponent', () => {
let component: ManageRolesComponent;
let fixture: ComponentFixture<ManageRolesComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [FormsModule],
providers: [HttpClient, HttpHandler],
declarations: [ManageRolesComponent, RoleModalComponent],
schemas: [NO_ERRORS_SCHEMA]
}).compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(ManageRolesComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should open the add modal', () => {
spyOn(component, 'onOpenAdd').and.callThrough();
expect(component.roleModal.visible).toBeTrue();
expect(component.roleModal.state).toBe(ModalRoleState.Add);
});
});
The onOpenAdd()
function is quite straightforward:
public onOpenAdd() {
this.roleModal.state = ModalRoleState.Add;
this.roleModal.open();
}
The same simplicity applies to the open()
function:
public open() {
this.visible = true;
}
I am puzzled as to why the test fails even though I am explicitly setting the value of visible
to true
. Is there something wrong with my approach or implementation? Any insights would be greatly appreciated.