refactor(facade): move isPromise to core private (#10573)

This commit is contained in:
Jason Choi
2016-09-18 15:55:08 -07:00
committed by Alex Eagle
parent 14ee75924b
commit df4254ae89
14 changed files with 95 additions and 35 deletions

View File

@ -113,12 +113,6 @@ export function isStrictStringMap(obj: any): boolean {
return isStringMap(obj) && Object.getPrototypeOf(obj) === STRING_MAP_PROTO;
}
export function isPromise(obj: any): boolean {
// allow any Promise/A+ compliant thenable.
// It's up to the caller to ensure that obj.then conforms to the spec
return isPresent(obj) && isFunction(obj.then);
}
export function isArray(obj: any): boolean {
return Array.isArray(obj);
}

View File

@ -6,7 +6,7 @@
* found in the LICENSE file at https://angular.io/license
*/
import {NumberWrapper, StringWrapper, escapeRegExp, hasConstructor, isPresent, isPromise, resolveEnumToken} from '../src/lang';
import {NumberWrapper, StringWrapper, escapeRegExp, hasConstructor, isPresent, resolveEnumToken} from '../src/lang';
enum UsefulEnum {
MyToken,
@ -153,22 +153,4 @@ export function main() {
() => { expect(hasConstructor(new MySubclass(), MySuperclass)).toEqual(false); });
});
});
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: function() {}})).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);
});
});
}