angular-cn/aio/content/examples/rx-library/src/error-handling.spec.ts
Kristiyan Kostadinov e86a1d3441 docs: make all examples compatible with strict mode (#41999)
Turns on the `strict` compiler flag and resolves the compilation errors in the various AIO examples.

PR Close #41999
2021-05-17 10:42:18 -07:00

47 lines
1.2 KiB
TypeScript

import { Subject, throwError } from 'rxjs';
import { docRegionDefault } from './error-handling';
describe('error-handling', () => {
let consoleSpy: jasmine.SpyObj<Console>;
let ajaxSubject: Subject<any>;
let ajax: jasmine.Spy;
beforeEach(() => {
consoleSpy = jasmine.createSpyObj<Console>('console', ['log']);
ajaxSubject = new Subject();
ajax = jasmine
.createSpy('ajax')
.and.callFake((url: string) => ajaxSubject);
});
afterEach(() => ajaxSubject.unsubscribe());
it('should return the response object', () => {
docRegionDefault(consoleSpy, ajax);
ajaxSubject.next({response: {foo: 'bar'}});
expect(consoleSpy.log.calls.allArgs()).toEqual([
['data: ', {foo: 'bar'}]
]);
});
it('should return an empty array when using an object without a `response` property', () => {
docRegionDefault(consoleSpy, ajax);
ajaxSubject.next({foo: 'bar'});
expect(consoleSpy.log.calls.allArgs()).toEqual([
['data: ', []]
]);
});
it('should return an empty array when the ajax observable errors', () => {
ajax.and.returnValue(throwError('Test Error'));
docRegionDefault(consoleSpy, ajax);
expect(consoleSpy.log.calls.allArgs()).toEqual([
['data: ', []]
]);
});
});