diff --git a/packages/core/test/linker/ng_container_integration_spec.ts b/packages/core/test/linker/ng_container_integration_spec.ts index 890a63e7ff..5b3ea1c78f 100644 --- a/packages/core/test/linker/ng_container_integration_spec.ts +++ b/packages/core/test/linker/ng_container_integration_spec.ts @@ -11,7 +11,7 @@ import {AfterContentInit, AfterViewInit, Component, ContentChildren, Directive, import {TestBed} from '@angular/core/testing'; import {getDOM} from '@angular/platform-browser/src/dom/dom_adapter'; import {expect} from '@angular/platform-browser/testing/src/matchers'; -import {fixmeIvy} from '@angular/private/testing'; +import {fixmeIvy, polyfillGoogGetMsg} from '@angular/private/testing'; { if (ivyEnabled) { @@ -26,6 +26,11 @@ function declareTests(config?: {useJit: boolean}) { describe('', function() { beforeEach(() => { + // Injecting goog.getMsg-like function into global scope to unblock tests run outside of + // Closure Compiler. It's a *temporary* measure until runtime translation service support is + // introduced. + polyfillGoogGetMsg(); + TestBed.configureCompiler({...config}); TestBed.configureTestingModule({ declarations: [ @@ -38,17 +43,16 @@ function declareTests(config?: {useJit: boolean}) { }); }); - fixmeIvy('FW-663: ReferenceError: goog is not defined') && - it('should support the "i18n" attribute', () => { - const template = 'foo'; - TestBed.overrideComponent(MyComp, {set: {template}}); - const fixture = TestBed.createComponent(MyComp); + it('should support the "i18n" attribute', () => { + const template = 'foo'; + TestBed.overrideComponent(MyComp, {set: {template}}); + const fixture = TestBed.createComponent(MyComp); - fixture.detectChanges(); + fixture.detectChanges(); - const el = fixture.nativeElement; - expect(el).toHaveText('foo'); - }); + const el = fixture.nativeElement; + expect(el).toHaveText('foo'); + }); fixmeIvy('FW-678: ivy generates different DOM structure for ') && it('should be rendered as comment with children as siblings', () => { diff --git a/packages/private/testing/index.ts b/packages/private/testing/index.ts index e8f3e5844c..692207570e 100644 --- a/packages/private/testing/index.ts +++ b/packages/private/testing/index.ts @@ -8,3 +8,4 @@ export * from './src/render3'; export * from './src/fixme'; +export * from './src/goog_get_msg'; diff --git a/packages/private/testing/src/goog_get_msg.ts b/packages/private/testing/src/goog_get_msg.ts new file mode 100644 index 0000000000..a4b63dcaf8 --- /dev/null +++ b/packages/private/testing/src/goog_get_msg.ts @@ -0,0 +1,25 @@ +/** + * @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 + */ + +/** + * A method that injects goog.getMsg-like function into global scope. + * + * This method is required as a *temporary* measure to prevent i18n tests from being blocked while + * running outside of Closure Compiler. This method will not be needed once runtime translation + * service support is introduced. + */ +export function polyfillGoogGetMsg(): void { + const glob = (global as any); + glob.goog = glob.goog || {}; + glob.goog.getMsg = + glob.goog.getMsg || function(input: string, placeholders: {[key: string]: string} = {}) { + return Object.keys(placeholders).length ? + input.replace(/\{\$(.*?)\}/g, (match, key) => placeholders[key] || '') : + input; + }; +}