ionic-team / ionic-team/cap-plugin-mock-jasmine

How to Unit Test App.addListener in Jasmine

Open
#1 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
4
Forks
2
PR merge metrics
No merged PRs in 30d

Description

Hi,

I am trying to write Jasmine unit tests for events passed from App.
Here is my code .ts file:

` public _disableBackButton(): void {
App.addListener('backButton', () => {
return;
});
}`

Here is .spec file:

it('should disable back button', fakeAsync(() => {
spyOn(App, 'addListener').and.callFake((type: string, fn: BackButtonListener) => {
return { type, fn };
});

component._disableBackButton();
App.addListener('backButton', () => ({}));
expect(App.addListener).toBeDefined();
}));

But it can't run into callFake.
The docs on testing seem limited, and I cannot see any issues on this. Am I missing a simple thing?

Thanks in advance!

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.