jeudi 28 novembre 2019

testing instanceof NavigationStart with jest

I know it's probably very stupid question. But if someone can help me with that it would be amazing. I was trying to test this part of code :

    public subject = new Subject<any>();
    public keepAfterNavigationChange = false;

    constructor(public router: Router) {
        // clear alert message on route change
        router.events.subscribe(event => {
            if (event instanceof NavigationStart) {
                if (this.keepAfterNavigationChange) {
                    // only keep for a single location change
                    this.keepAfterNavigationChange = false;
                } else {
                    // clear alert
                    this.subject.next();
                }
            }
        });
    }

But coverage is always showing that this function is not covered:

event => {
            if (event instanceof NavigationStart) {
                if (this.keepAfterNavigationChange) {
                    // only keep for a single location change
                    this.keepAfterNavigationChange = false;
                } else {
                    // clear alert
                    this.subject.next();
                }
            }

How exactly should I test it?

Aucun commentaire:

Enregistrer un commentaire