In my Angular application, I'm writing some integration tests where I have an ngx-bootstrap modal
In my integration tests, I'm testing a Component which contains a button that pops up a modal. Inside a modal, there is a "Save" button which is clicked during the tests.
Inside the Modal Component, the button triggers a method on click:
(click)=onSave()
and this is how the Modal Component looks like:
constructor(
protected bsModalRef: BsModalRef,
) {}
onSave() {
// do some stuff (NOTE: this part is actually executed during the test)
this.bsModalRef.hide();
}
Everything works fine, except that the modal won't disappear. However the onSave()
method is correctly executed.
That is very strange, because if I manually click on the button after the test has finished to run, it correctly hides the modal
But during the test, despite the button correctly receives the click and triggers the execution of the onSave()
method, the modal does not disapper.
Note: there are no spies involved here and, since it's an integration test, I would prefer to not mock the hide()
method but to actually make it work during the test and then assert that the modal has correctly disappeared together with the other side-effects of my custom onSave()
method.