2016-10-19 20:41:04 +00:00
|
|
|
/**
|
|
|
|
|
* @license
|
2020-05-19 19:08:49 +00:00
|
|
|
* Copyright Google LLC All Rights Reserved.
|
2016-10-19 20:41:04 +00:00
|
|
|
*
|
|
|
|
|
* 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
|
|
|
|
|
*/
|
|
|
|
|
|
2019-03-22 09:42:52 +00:00
|
|
|
import {Ng1Token} from '../../src/common/src/angular1';
|
2024-01-30 18:04:57 +00:00
|
|
|
import {
|
|
|
|
|
compileFactory,
|
|
|
|
|
injectorFactory,
|
|
|
|
|
parseFactory,
|
|
|
|
|
rootScopeFactory,
|
|
|
|
|
setTempInjectorRef,
|
|
|
|
|
} from '../src/angular1_providers';
|
2016-10-19 20:41:04 +00:00
|
|
|
|
2023-10-17 09:45:16 +00:00
|
|
|
describe('upgrade angular1_providers', () => {
|
|
|
|
|
describe('compileFactory', () => {
|
|
|
|
|
it('should retrieve and return `$compile`', () => {
|
|
|
|
|
const services: {[key: string]: any} = {$compile: 'foo'};
|
|
|
|
|
const mockInjector = {get: (name: Ng1Token): any => services[name], has: () => true};
|
2016-10-19 20:41:04 +00:00
|
|
|
|
2023-10-17 09:45:16 +00:00
|
|
|
expect(compileFactory(mockInjector)).toBe('foo');
|
2016-10-19 20:41:04 +00:00
|
|
|
});
|
2023-10-17 09:45:16 +00:00
|
|
|
});
|
2016-10-19 20:41:04 +00:00
|
|
|
|
2023-10-17 09:45:16 +00:00
|
|
|
describe('injectorFactory', () => {
|
|
|
|
|
it('should return the injector value that was previously set', () => {
|
|
|
|
|
const mockInjector = {get: () => undefined, has: () => false};
|
|
|
|
|
setTempInjectorRef(mockInjector);
|
|
|
|
|
const injector = injectorFactory();
|
|
|
|
|
expect(injector).toBe(mockInjector);
|
|
|
|
|
});
|
2016-10-19 20:41:04 +00:00
|
|
|
|
2023-10-17 09:45:16 +00:00
|
|
|
it('should throw if the injector value is not set', () => {
|
|
|
|
|
// Ensure the injector is not set. This shouldn't be necessary, but on CI there seems to be
|
|
|
|
|
// some race condition with previous tests not being cleaned up properly.
|
|
|
|
|
// Related:
|
|
|
|
|
// - https://github.com/angular/angular/pull/28045
|
|
|
|
|
// - https://github.com/angular/angular/pull/28181
|
|
|
|
|
setTempInjectorRef(null as any);
|
2019-01-10 15:18:05 +00:00
|
|
|
|
2023-10-17 09:45:16 +00:00
|
|
|
expect(injectorFactory).toThrowError();
|
|
|
|
|
});
|
2017-07-20 16:06:13 +00:00
|
|
|
|
2023-10-17 09:45:16 +00:00
|
|
|
it('should unset the injector after the first call (to prevent memory leaks)', () => {
|
|
|
|
|
const mockInjector = {get: () => undefined, has: () => false};
|
|
|
|
|
setTempInjectorRef(mockInjector);
|
|
|
|
|
injectorFactory();
|
2024-01-30 18:04:57 +00:00
|
|
|
expect(injectorFactory).toThrowError(); // ...because it has been unset
|
2016-10-19 20:41:04 +00:00
|
|
|
});
|
2023-10-17 09:45:16 +00:00
|
|
|
});
|
2016-10-19 20:41:04 +00:00
|
|
|
|
2023-10-17 09:45:16 +00:00
|
|
|
describe('parseFactory', () => {
|
|
|
|
|
it('should retrieve and return `$parse`', () => {
|
|
|
|
|
const services: {[key: string]: any} = {$parse: 'bar'};
|
|
|
|
|
const mockInjector = {get: (name: Ng1Token): any => services[name], has: () => true};
|
2016-10-19 20:41:04 +00:00
|
|
|
|
2023-10-17 09:45:16 +00:00
|
|
|
expect(parseFactory(mockInjector)).toBe('bar');
|
2016-10-19 20:41:04 +00:00
|
|
|
});
|
2023-10-17 09:45:16 +00:00
|
|
|
});
|
2016-10-19 20:41:04 +00:00
|
|
|
|
2023-10-17 09:45:16 +00:00
|
|
|
describe('rootScopeFactory', () => {
|
|
|
|
|
it('should retrieve and return `$rootScope`', () => {
|
|
|
|
|
const services: {[key: string]: any} = {$rootScope: 'baz'};
|
|
|
|
|
const mockInjector = {get: (name: Ng1Token): any => services[name], has: () => true};
|
2016-10-19 20:41:04 +00:00
|
|
|
|
2023-10-17 09:45:16 +00:00
|
|
|
expect(rootScopeFactory(mockInjector)).toBe('baz');
|
2016-10-19 20:41:04 +00:00
|
|
|
});
|
|
|
|
|
});
|
2023-10-17 09:45:16 +00:00
|
|
|
});
|