Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it('should show quote after getQuote (marbles)', () => {
// observable test quote value and complete(), after delay
// #docregion test-quote-marbles
const q$ = cold('---x|', { x: testQuote });
// #enddocregion test-quote-marbles
getQuoteSpy.and.returnValue( q$ );
fixture.detectChanges(); // ngOnInit()
expect(quoteEl.textContent).toBe('...', 'should show placeholder');
// #docregion test-scheduler-flush
getTestScheduler().flush(); // flush the observables
// #enddocregion test-scheduler-flush
fixture.detectChanges(); // update view
expect(quoteEl.textContent).toBe(testQuote, 'should show quote');
expect(errorMessage()).toBeNull('should not show error');
});
// #enddocregion get-quote-test
it('should return a LoadConfigsSuccess when the configService serve configuration', () => {
const expectedConfig = {value: {subValue1: 1, subValue2: 2}};
const localActions$ = new Actions(hot('-a--', {a: new LoadConfig()}));
// const localMockConfigService = jasmine.createSpyObj('ConfigService', ['fetchConfiguration']);
configService.fetchConfiguration.and.returnValue(hot('---b', {b: expectedConfig}));
const expectedAction = new LoadConfigSuccess({config: expectedConfig});
const localExpected = hot('---c', {c: expectedAction});
effects = new ConfigEffects(mockStore, localActions$, configService);
expect(effects).toBeTruthy();
expect(effects.loadConfiguration).toBeObservable(localExpected);
});
it('should return a LoadConfigsFailure when the configService doesn\'t serve configuration', () => {
it('should trigger ClearLightCardSelection if navigating from feed/cards/* to somewhere else', () => {
const navigation = {
type: ROUTER_REQUEST,
payload: {
routerState: {
url: "/feed/cards/myCardId"
},
event: new NavigationStart(1,"/archive/")
}
}
const localActions$ = new Actions(hot('-a-', { a: navigation}));
const expectedAction = new ClearLightCardSelection();
const localExpected = hot('-b-', {b: expectedAction});
effects = new CustomRouterEffects(mockStore, localActions$);
expect(effects).toBeTruthy();
expect(effects.navigateAwayFromFeed).toBeObservable(localExpected);
});
test(`should handle a delay with a specific retry date time`, () => {
const waitTime = time(`${'-'.repeat(100) }|`);
const emissionTime = new Date(getTestScheduler().now() + waitTime);
const retryErrorWithSpecificDelay = new HttpErrorResponse({
status: 429,
headers: new HttpHeaders({ 'Retry-After': emissionTime.toString() }),
});
getTestScheduler().maxFrames = 1500;
(expect(
errorAfter(3, retryErrorWithSpecificDelay, 1).pipe(
httpRetryer({ scheduler: getTestScheduler() }),
),
) as any).toBeObservable(
// Note the '- 2' account for the time it takes to get to the first error
cold(`ab${ '-'.repeat(100 - 2) }abcd`, {
a: 1,
b: 2,
c: 3,
d: 4,
}),
);
});
test(`should handle a delay with a specific retry date time`, () => {
const waitTime = time(`${'-'.repeat(100) }|`);
const emissionTime = new Date(getTestScheduler().now() + waitTime);
const retryErrorWithSpecificDelay = new HttpErrorResponse({
status: 429,
headers: new HttpHeaders({ 'Retry-After': emissionTime.toString() }),
});
getTestScheduler().maxFrames = 1500;
(expect(
errorAfter(3, retryErrorWithSpecificDelay, 1).pipe(
httpRetryer({ scheduler: getTestScheduler() }),
),
) as any).toBeObservable(
// Note the '- 2' account for the time it takes to get to the first error
cold(`ab${ '-'.repeat(100 - 2) }abcd`, {
// there is no i18n file referenced in the store
const cachedI18n$ = hot('-b', {b:new Map>()});
storeMock.select.withArgs(selectI18nUpLoaded).and.returnValue(cachedI18n$);
expect(underTest).toBeTruthy();
// an UpdateTranslation is expected
const expectedVersions=new Set(lightCards.map(card=>card.publisherVersion));
const expectedThirdAndVersion=generateThirdWithVersion('testPublisher',expectedVersions);
const expectedEmittedActions = hot('-c'
, {
c: new UpdateTranslation({versions: expectedThirdAndVersion})
});
expect(underTest.verifyTranslationNeeded).toBeObservable(expectedEmittedActions);
});
it('should return a [ngrx-forms] SetErrors action if the register service throws', () => {
const result = {
error: {
errors: { invalid: 'Invalid data' } as Errors,
},
};
const registerAction = AuthActions.register();
const setErrors = new SetErrors(result.error.errors);
actions$ = hot('-a---', { a: registerAction });
const response = cold('-#', {}, result);
service.register = jest.fn(() => response);
const expected = cold('--b', { b: setErrors });
expect(effects.register$).toBeObservable(expected);
});
});
it("should dispatch a showMessageAction", () => {
const message = {
type: MessageType.Success,
content: "Job Created Successfully",
duration: 5000
};
const action = fromActions.submitJobCompleteAction({ job });
const outcome = showMessageAction({ message });
actions = hot("-a", { a: action });
const expected = cold("-b", { b: outcome });
expect(effects.submitJobCompleteMessage$).toBeObservable(expected);
});
});
it("CheckExportStatus should dispatch another CheckExportStatus action if the download isn't ready", () => {
actions = hot('a', {
a: new Actions.CheckExportStatus({ reportId, taskId }),
});
const response = cold('-b', { b: { state: 'newp' } });
const expected = cold(delay + 'c', {
c: new Actions.CheckExportStatus({ reportId, taskId }),
});
service.checkStatus.and.returnValue(response);
expect(effects.checkExportStatus$).toBeObservable(expected);
});
it('should initialize product$', () => {
facade.product$ = hot('ab', { a: null, b: mockProduct });
component.ngOnInit();
const expected = cold('ab', { a: null, b: mockProduct });
expect(component.product$).toBeObservable(expected);
});