2016-09-18 18:55:08 -04:00
|
|
|
/**
|
|
|
|
* @license
|
2020-05-19 15:08:49 -04:00
|
|
|
* Copyright Google LLC All Rights Reserved.
|
2016-09-18 18:55:08 -04:00
|
|
|
*
|
|
|
|
* Use of this source code is governed by an MIT-style license that can be
|
|
|
|
* found in the LICENSE file at https://angular.io/license
|
|
|
|
*/
|
2019-11-27 16:00:59 -05:00
|
|
|
import {isObservable, isPromise} from '@angular/core/src/util/lang';
|
2020-04-13 19:40:21 -04:00
|
|
|
import {of} from 'rxjs';
|
2016-09-18 18:55:08 -04:00
|
|
|
|
2017-12-15 19:28:41 -05:00
|
|
|
{
|
2016-09-18 18:55:08 -04:00
|
|
|
describe('isPromise', () => {
|
|
|
|
it('should be true for native Promises',
|
|
|
|
() => expect(isPromise(Promise.resolve(true))).toEqual(true));
|
|
|
|
|
|
|
|
it('should be true for thenables', () => expect(isPromise({then: () => {}})).toEqual(true));
|
|
|
|
|
|
|
|
it('should be false if "then" is not a function',
|
|
|
|
() => expect(isPromise({then: 0})).toEqual(false));
|
|
|
|
|
|
|
|
it('should be false if the argument has no "then" function',
|
|
|
|
() => expect(isPromise({})).toEqual(false));
|
|
|
|
|
|
|
|
it('should be false if the argument is undefined or null', () => {
|
|
|
|
expect(isPromise(undefined)).toEqual(false);
|
|
|
|
expect(isPromise(null)).toEqual(false);
|
|
|
|
});
|
|
|
|
});
|
2019-11-27 16:00:59 -05:00
|
|
|
|
|
|
|
describe('isObservable', () => {
|
2020-04-13 19:40:21 -04:00
|
|
|
it('should be true for an Observable', () => expect(isObservable(of(true))).toEqual(true));
|
2019-11-27 16:00:59 -05:00
|
|
|
|
|
|
|
it('should be true if the argument is the object with subscribe function',
|
|
|
|
() => expect(isObservable({subscribe: () => {}})).toEqual(true));
|
|
|
|
|
|
|
|
it('should be false if the argument is undefined',
|
|
|
|
() => expect(isObservable(undefined)).toEqual(false));
|
|
|
|
|
|
|
|
it('should be false if the argument is null', () => expect(isObservable(null)).toEqual(false));
|
|
|
|
|
|
|
|
it('should be false if the argument is an object',
|
|
|
|
() => expect(isObservable({})).toEqual(false));
|
|
|
|
|
|
|
|
it('should be false if the argument is a function',
|
|
|
|
() => expect(isObservable(() => {})).toEqual(false));
|
|
|
|
});
|
2016-09-18 18:55:08 -04:00
|
|
|
}
|