Как протестировать хуки жизненного цикла Angular в Testing-библиотеке? - PullRequest
0 голосов
/ 09 июля 2020

Вот мой ngAfterViewInit хук, который отправляет пару событий:

ngAfterViewInit() {
        // this.cdRef.detectChanges();
        this.store.dispatch(
            PmActions.setBreadcrumbNavigationCheck({ breadcrumbNavigate: true })
        );
        this.store.dispatch(actionsTitle.SubTitles({ value: 'heading' }));
    }

    ngOnDestroy() {
        this.store.dispatch(courseAttrActions.LoadFailure_CR({ error: null }));
    }

Как я могу написать тест ловушек likecycycle?

Моя попытка не работает.

test('shell view should call ngAfterViewInit with dispatch of Breadcrumb and title', async () => {

        const actionTitle = { type: '[setup-config] GetSubTitles' }
        const actionBreadCrumb = { type: '[setup-config] setUpconfigBreadcrumbCheckx' } //it should throw error but not doing it!

        store.scannedActions$.pipe(skip(1)).subscribe(scannedAction => {
            expect(scannedAction).toEqual(actionBreadCrumb);
        });
        
        store.scannedActions$.pipe(skip(1)).subscribe(scannedAction => {
            expect(scannedAction).toEqual(actionTitle);
        });

        instant.ngAfterViewInit();
        fixture.detectChanges();


    });
...