fix(SyncAsyncResult): fix default async value (#10013)

This commit is contained in:
Victor Berchet 2016-07-12 13:55:06 -07:00 committed by GitHub
parent ded518d47f
commit 6d02d2f107
2 changed files with 25 additions and 1 deletions

View File

@ -93,7 +93,7 @@ export function createDiTokenExpression(token: CompileTokenMetadata): o.Expressi
export class SyncAsyncResult<T> {
constructor(public syncResult: T, public asyncResult: Promise<T> = null) {
if (!asyncResult) {
asyncResult = Promise.resolve(syncResult);
this.asyncResult = Promise.resolve(syncResult);
}
}
}

View File

@ -0,0 +1,24 @@
/**
* @license
* Copyright Google Inc. All Rights Reserved.
*
* 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
*/
import {fakeAsync, flushMicrotasks} from '@angular/core/testing/fake_async';
import {beforeEach, beforeEachProviders, ddescribe, describe, expect, iit, inject, it, xit} from '@angular/core/testing/testing_internal';
import {SyncAsyncResult} from '../src/util';
export function main() {
describe('util', () => {
describe('SyncAsyncResult', () => {
it('async value should default to Promise.resolve(syncValue)', fakeAsync(() => {
const syncValue = {};
const sar = new SyncAsyncResult(syncValue);
sar.asyncResult.then((v: any) => expect(v).toBe(syncValue));
}));
});
})
}