本文整理汇总了TypeScript中@angular/core/testing.flush函数的典型用法代码示例。如果您正苦于以下问题:TypeScript flush函数的具体用法?TypeScript flush怎么用?TypeScript flush使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了flush函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: flush
fixture.ngZone.run(() => {
router = TestBed.get(Router);
router.initialNavigation();
// Generate breadcrumb items.
router.navigate([ 'one', 'two', 'three', 'four' ]);
fixture.detectChanges();
flush();
fixture.detectChanges();
items = fixture.debugElement.queryAll(By.directive(NzBreadCrumbItemComponent));
// Should generate 2 breadcrumbs when reaching out of the `data` scope.
expect(breadcrumb.componentInstance.breadcrumbs.length).toBe(2);
dispatchMouseEvent(items[ 1 ].nativeElement.querySelector('a'), 'click');
router.navigate([ 'one', 'two', 'three' ]);
fixture.detectChanges();
flush();
fixture.detectChanges();
expect(breadcrumb.componentInstance.breadcrumbs.length).toBe(2);
router.navigate([ 'one', 'two' ]);
fixture.detectChanges();
flush();
fixture.detectChanges();
expect(breadcrumb.componentInstance.breadcrumbs.length).toBe(1);
router.navigate([ 'one' ]);
fixture.detectChanges();
flush();
fixture.detectChanges();
// Shouldn't generate breadcrumb at all.
expect(breadcrumb.componentInstance.breadcrumbs.length).toBe(0);
});
示例2: it
it('should create site when form is valid', fakeAsync(() => {
findSitesSpy.and.returnValue(Promise.resolve(findSitesResponse));
spyOn(alfrescoApi.sitesApi, 'createSite').and.returnValue(
Promise.resolve()
);
spyOn(alfrescoApi.sitesApi, 'getSite').and.callFake(() => {
return new Promise((resolve, reject) => reject());
});
fixture.detectChanges();
component.form.controls.title.setValue('library title');
tick(500);
flush();
fixture.detectChanges();
component.submit();
fixture.detectChanges();
flush();
expect(alfrescoApi.sitesApi.createSite).toHaveBeenCalledWith({
id: 'library-title',
title: 'library title',
description: '',
visibility: 'PUBLIC'
});
}));
示例3: fakeAsync
+ 'sync repository. When confirmed, open settings dialog.', fakeAsync(() => {
(vcs.canSyncRepository as Spy).and.returnValue(Promise.resolve(false));
getSyncWorkspaceButtonEl().click();
flush();
const confirmDialog = mockDialog.getByComponent<ConfirmDialogComponent,
ConfirmDialogData,
boolean>(
ConfirmDialogComponent,
);
expect(confirmDialog).toBeDefined();
expect(confirmDialog.config.data.isAlert).toBe(false);
confirmDialog.close(true);
flush();
const settingsDialog = mockDialog.getByComponent<SettingsDialogComponent,
SettingsDialogData,
void>(
SettingsDialogComponent,
);
expect(settingsDialog).toBeDefined();
expect(settingsDialog.config.data.initialSettingId).toEqual(VCS_SETTINGS_ID);
}));
示例4: it
it('should throw error and redirect user if he has not logged in', fakeAsync(() => {
spyOn(dashboardService, 'getProgressStatus').and.returnValue(throwError({error: 'ERROR'}));
spyOn(languageService, 'loadLanguage').and.returnValue(Observable.of(languageData));
flush();
component.ngOnInit();
fixture.detectChanges();
flush();
expect(router.navigate).toHaveBeenCalledWith(['/login']);
}));
示例5: it
it("reacts to save click", fakeAsync(() => {
component.ngOnInit();
component.click();
httpAction.next({ url: '', method: HttpMethod.Post, isComplete: false });
flush();
expect(component.isSaving).toBeTruthy();
httpAction.next({ url: '', method: HttpMethod.Post, isComplete: true });
flush();
expect(component.isSaving).toBeFalsy();
expect(component.isListening).toBeFalsy();
}));
示例6: fakeAsync
+ '\'TEXT\'. And dispatch NoteSnippetEditorInsertImageEvent when user select file.', fakeAsync(() => {
const selectedNote = noteDummy.create();
const content = contentDummy.create();
content.snippets[0] = new NoteSnippetContentDummy().create(NoteSnippetTypes.TEXT);
ensureSelectNoteAndLoadNoteContent(selectedNote, content);
activateSnippetAtIndex(0);
fixture.detectChanges();
spyOn(nativeDialog, 'showOpenDialog').and.returnValue(of({
isSelected: true,
filePaths: ['/foo/bar/assets/some-image.png'],
} as NativeDialogOpenResult));
spyOn(noteEditor, 'copyAssetFile').and.returnValue(of({
fileNameWithoutExtension: 'some-image',
relativePathToWorkspaceDir: './some-image.png',
} as Asset));
menuMessages.next(MenuEvent.INSERT_IMAGE);
flush();
flush();
flush();
expect(nativeDialog.showOpenDialog).toHaveBeenCalledWith({
message: 'Choose an image:',
properties: NativeDialogProperties.OPEN_FILE,
fileFilters: [nativeDialogFileFilters.IMAGES],
} as NativeDialogConfig);
expect(noteEditor.copyAssetFile).toHaveBeenCalledWith(
AssetTypes.IMAGE,
selectedNote.contentFilePath,
'/foo/bar/assets/some-image.png',
);
expect(listManager.handleSnippetRefEvent).toHaveBeenCalled();
const event = (
listManager.handleSnippetRefEvent as Spy
).calls.first().args[0] as NoteSnippetEditorInsertImageEvent;
// noinspection SuspiciousInstanceOfGuard
expect(event instanceof NoteSnippetEditorInsertImageEvent).toBe(true);
expect(event.payload.fileName).toEqual('some-image');
expect(event.payload.filePath).toEqual('./some-image.png');
discardPeriodicTasks();
}));
示例7: it
it('should open alert when \'VcsPrimaryEmailNotExists\' exception thrown.', fakeAsync(() => {
makeAccountsToBeLoadedWith();
fixture.detectChanges();
flush();
fixture.detectChanges();
switchAuthMethodOption(VcsAuthenticationTypes.OAUTH2_TOKEN);
typeInElement('token', getTokenInputEl());
fixture.detectChanges();
const newAccount: VcsAccount = {
...vcsAccountDummy.create(VcsAuthenticationTypes.OAUTH2_TOKEN),
email: null,
};
spyOn(github, 'authorizeByOauth2Token').and.returnValue(of(newAccount));
spyOn(github, 'getPrimaryEmail').and.returnValue(throwError(new VcsPrimaryEmailNotExistsError()));
getLoginAndAddAccountButtonEl().click();
fixture.detectChanges();
const alert = thisMockDialog.getByComponent<ConfirmDialogComponent,
ConfirmDialogData,
boolean>(
ConfirmDialogComponent,
);
expect(alert).toBeDefined();
expect(alert.config.data.title).toEqual('Cannot read email from github.com');
expect(alert.config.data.isAlert).toEqual(true);
}));
示例8: fakeAsync
+ 'should reset form.', fakeAsync(() => {
makeAccountsToBeLoadedWith();
fixture.detectChanges();
flush();
fixture.detectChanges();
switchAuthMethodOption(VcsAuthenticationTypes.OAUTH2_TOKEN);
typeInElement('token', getTokenInputEl());
fixture.detectChanges();
const newAccount = vcsAccountDummy.create(VcsAuthenticationTypes.OAUTH2_TOKEN);
spyOn(github, 'authorizeByOauth2Token').and.returnValue(of(newAccount));
spyOn(accountDB, 'addNewAccount').and.callThrough();
getLoginAndAddAccountButtonEl().click();
fixture.detectChanges();
expect(github.authorizeByOauth2Token).toHaveBeenCalledWith('token');
expect(accountDB.addNewAccount).toHaveBeenCalledWith(newAccount);
// Should form reset
expect(component.addAccountFormGroup.value).toEqual({
type: VcsAuthenticationTypes.OAUTH2_TOKEN,
userName: '',
password: '',
token: '',
});
}));
示例9: it
it('should disable the tooltip', fakeAsync(() => {
const fixture: ComponentFixture<
CalendarMonthViewComponent
> = TestBed.createComponent(CalendarMonthViewComponent);
eventTitle.monthTooltip = () => '';
fixture.componentInstance.viewDate = new Date('2016-06-27');
fixture.componentInstance.events = [
{
start: new Date('2016-05-30'),
end: new Date('2016-06-02'),
title: 'foo <b>bar</b>',
color: {
primary: 'blue',
secondary: 'rgb(238, 238, 238)'
}
}
];
fixture.componentInstance.ngOnChanges({ viewDate: {}, events: {} });
fixture.detectChanges();
const event: HTMLElement = fixture.nativeElement.querySelector(
'.cal-days .cal-cell-row .cal-cell:nth-child(4) .cal-events .cal-event'
);
triggerDomEvent('mouseenter', event);
fixture.detectChanges();
flush();
expect(!!document.body.querySelector('.cal-tooltip')).to.equal(false);
}));
示例10: it
it('should flush tasks', fakeAsync(() => {
let ran = false;
setTimeout(() => { ran = true; }, 10);
flush();
expect(ran).toEqual(true);
}));