mirror of
https://github.com/angular/angular.git
synced 2026-11-23 23:17:50 -05:00
This commits add a utility method to merge multiple `ApplicationConfiguration` into one from left to right. This is useful for server rendering were an application might have several configurations. Usage Example: ```ts const config = mergeApplicationConfig(appConfig, appServerConfig); ``` PR Close #49253
57 lines
1.7 KiB
TypeScript
57 lines
1.7 KiB
TypeScript
/**
|
|
* @license
|
|
* Copyright Google LLC 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 {ApplicationConfig, InjectionToken, mergeApplicationConfig} from '@angular/core';
|
|
|
|
describe('ApplicationConfig', () => {
|
|
describe('mergeApplicationConfig', () => {
|
|
const FOO_TOKEN = new InjectionToken('foo');
|
|
const BAR_TOKEN = new InjectionToken('bar');
|
|
const BUZ_TOKEN = new InjectionToken('buz');
|
|
|
|
const BASE_CONFIG: ApplicationConfig = {
|
|
providers: [{provide: FOO_TOKEN, useValue: 'foo'}],
|
|
};
|
|
|
|
const APP_CONFIG_EXPECT: ApplicationConfig = {
|
|
providers: [
|
|
{provide: FOO_TOKEN, useValue: 'foo'},
|
|
{provide: BAR_TOKEN, useValue: 'bar'},
|
|
{provide: BUZ_TOKEN, useValue: 'buz'},
|
|
]
|
|
};
|
|
|
|
it('should merge 2 configs from left to right', () => {
|
|
const extraConfig: ApplicationConfig = {
|
|
providers: [
|
|
{provide: BAR_TOKEN, useValue: 'bar'},
|
|
{provide: BUZ_TOKEN, useValue: 'buz'},
|
|
],
|
|
};
|
|
|
|
const config = mergeApplicationConfig(BASE_CONFIG, extraConfig);
|
|
expect(config).toEqual(APP_CONFIG_EXPECT);
|
|
});
|
|
|
|
it('should merge more than 2 configs from left to right', () => {
|
|
const extraConfigOne: ApplicationConfig = {
|
|
providers: [
|
|
{provide: BAR_TOKEN, useValue: 'bar'},
|
|
],
|
|
};
|
|
const extraConfigTwo: ApplicationConfig = {
|
|
providers: [
|
|
{provide: BUZ_TOKEN, useValue: 'buz'},
|
|
],
|
|
};
|
|
|
|
const config = mergeApplicationConfig(BASE_CONFIG, extraConfigOne, extraConfigTwo);
|
|
expect(config).toEqual(APP_CONFIG_EXPECT);
|
|
});
|
|
});
|
|
});
|