fix(ivy): add polyfill for goog.getMsg to unblock tests (FW-663) (#27218)
PR Close #27218
This commit is contained in:
parent
8424f587b0
commit
7773d7f552
|
@ -11,7 +11,7 @@ import {AfterContentInit, AfterViewInit, Component, ContentChildren, Directive,
|
||||||
import {TestBed} from '@angular/core/testing';
|
import {TestBed} from '@angular/core/testing';
|
||||||
import {getDOM} from '@angular/platform-browser/src/dom/dom_adapter';
|
import {getDOM} from '@angular/platform-browser/src/dom/dom_adapter';
|
||||||
import {expect} from '@angular/platform-browser/testing/src/matchers';
|
import {expect} from '@angular/platform-browser/testing/src/matchers';
|
||||||
import {fixmeIvy} from '@angular/private/testing';
|
import {fixmeIvy, polyfillGoogGetMsg} from '@angular/private/testing';
|
||||||
|
|
||||||
{
|
{
|
||||||
if (ivyEnabled) {
|
if (ivyEnabled) {
|
||||||
|
@ -26,6 +26,11 @@ function declareTests(config?: {useJit: boolean}) {
|
||||||
describe('<ng-container>', function() {
|
describe('<ng-container>', function() {
|
||||||
|
|
||||||
beforeEach(() => {
|
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.configureCompiler({...config});
|
||||||
TestBed.configureTestingModule({
|
TestBed.configureTestingModule({
|
||||||
declarations: [
|
declarations: [
|
||||||
|
@ -38,17 +43,16 @@ function declareTests(config?: {useJit: boolean}) {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
fixmeIvy('FW-663: ReferenceError: goog is not defined') &&
|
it('should support the "i18n" attribute', () => {
|
||||||
it('should support the "i18n" attribute', () => {
|
const template = '<ng-container i18n>foo</ng-container>';
|
||||||
const template = '<ng-container i18n>foo</ng-container>';
|
TestBed.overrideComponent(MyComp, {set: {template}});
|
||||||
TestBed.overrideComponent(MyComp, {set: {template}});
|
const fixture = TestBed.createComponent(MyComp);
|
||||||
const fixture = TestBed.createComponent(MyComp);
|
|
||||||
|
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
|
|
||||||
const el = fixture.nativeElement;
|
const el = fixture.nativeElement;
|
||||||
expect(el).toHaveText('foo');
|
expect(el).toHaveText('foo');
|
||||||
});
|
});
|
||||||
|
|
||||||
fixmeIvy('FW-678: ivy generates different DOM structure for <ng-container>') &&
|
fixmeIvy('FW-678: ivy generates different DOM structure for <ng-container>') &&
|
||||||
it('should be rendered as comment with children as siblings', () => {
|
it('should be rendered as comment with children as siblings', () => {
|
||||||
|
|
|
@ -8,3 +8,4 @@
|
||||||
|
|
||||||
export * from './src/render3';
|
export * from './src/render3';
|
||||||
export * from './src/fixme';
|
export * from './src/fixme';
|
||||||
|
export * from './src/goog_get_msg';
|
||||||
|
|
|
@ -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;
|
||||||
|
};
|
||||||
|
}
|
Loading…
Reference in New Issue