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 {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('<ng-container>', 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,7 +43,6 @@ function declareTests(config?: {useJit: boolean}) {
|
|||
});
|
||||
});
|
||||
|
||||
fixmeIvy('FW-663: ReferenceError: goog is not defined') &&
|
||||
it('should support the "i18n" attribute', () => {
|
||||
const template = '<ng-container i18n>foo</ng-container>';
|
||||
TestBed.overrideComponent(MyComp, {set: {template}});
|
||||
|
|
|
@ -8,3 +8,4 @@
|
|||
|
||||
export * from './src/render3';
|
||||
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