From 6d02d2f107555a27f693ceb85b559609cc056723 Mon Sep 17 00:00:00 2001 From: Victor Berchet Date: Tue, 12 Jul 2016 13:55:06 -0700 Subject: [PATCH] fix(SyncAsyncResult): fix default async value (#10013) --- modules/@angular/compiler/src/util.ts | 2 +- modules/@angular/compiler/test/util_spec.ts | 24 +++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 modules/@angular/compiler/test/util_spec.ts diff --git a/modules/@angular/compiler/src/util.ts b/modules/@angular/compiler/src/util.ts index e3c53cbbe0..4013b3a6c7 100644 --- a/modules/@angular/compiler/src/util.ts +++ b/modules/@angular/compiler/src/util.ts @@ -93,7 +93,7 @@ export function createDiTokenExpression(token: CompileTokenMetadata): o.Expressi export class SyncAsyncResult { constructor(public syncResult: T, public asyncResult: Promise = null) { if (!asyncResult) { - asyncResult = Promise.resolve(syncResult); + this.asyncResult = Promise.resolve(syncResult); } } } diff --git a/modules/@angular/compiler/test/util_spec.ts b/modules/@angular/compiler/test/util_spec.ts new file mode 100644 index 0000000000..7ef4dc9d9f --- /dev/null +++ b/modules/@angular/compiler/test/util_spec.ts @@ -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)); + })); + }); + }) +}