2018-04-12 15:30:21 -04:00
|
|
|
/**
|
|
|
|
* @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
|
|
|
|
*/
|
|
|
|
|
2018-07-12 18:10:55 -04:00
|
|
|
import {MockDirectory, setup} from '@angular/compiler/test/aot/test_util';
|
2018-04-12 15:30:21 -04:00
|
|
|
import {compile, expectEmit} from './mock_compile';
|
|
|
|
|
|
|
|
describe('compiler compliance: dependency injection', () => {
|
|
|
|
const angularFiles = setup({
|
2018-08-01 03:52:34 -04:00
|
|
|
compileAngular: false,
|
|
|
|
compileFakeCore: true,
|
2018-04-12 15:30:21 -04:00
|
|
|
compileAnimations: false,
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should create factory methods', () => {
|
|
|
|
const files = {
|
|
|
|
app: {
|
|
|
|
'spec.ts': `
|
|
|
|
import {Component, NgModule, Injectable, Attribute, Host, SkipSelf, Self, Optional} from '@angular/core';
|
|
|
|
|
|
|
|
@Injectable()
|
|
|
|
export class MyService {}
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'my-component',
|
|
|
|
template: \`\`
|
|
|
|
})
|
|
|
|
export class MyComponent {
|
|
|
|
constructor(
|
|
|
|
@Attribute('name') name:string,
|
|
|
|
s1: MyService,
|
|
|
|
@Host() s2: MyService,
|
|
|
|
@Self() s4: MyService,
|
|
|
|
@SkipSelf() s3: MyService,
|
|
|
|
@Optional() s5: MyService,
|
|
|
|
@Self() @Optional() s6: MyService,
|
|
|
|
) {}
|
|
|
|
}
|
|
|
|
|
2018-08-01 03:52:34 -04:00
|
|
|
@NgModule({declarations: [MyComponent], providers: [MyService]})
|
2018-04-12 15:30:21 -04:00
|
|
|
export class MyModule {}
|
|
|
|
`
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
const factory = `
|
2018-07-16 19:36:31 -04:00
|
|
|
factory: function MyComponent_Factory(t) {
|
|
|
|
return new (t || MyComponent)(
|
2018-04-12 15:30:21 -04:00
|
|
|
$r3$.ɵinjectAttribute('name'),
|
|
|
|
$r3$.ɵdirectiveInject(MyService),
|
2018-04-12 18:54:16 -04:00
|
|
|
$r3$.ɵdirectiveInject(MyService, 1),
|
|
|
|
$r3$.ɵdirectiveInject(MyService, 2),
|
|
|
|
$r3$.ɵdirectiveInject(MyService, 4),
|
|
|
|
$r3$.ɵdirectiveInject(MyService, 8),
|
|
|
|
$r3$.ɵdirectiveInject(MyService, 10)
|
2018-04-12 15:30:21 -04:00
|
|
|
);
|
|
|
|
}`;
|
|
|
|
|
|
|
|
|
|
|
|
const result = compile(files, angularFiles);
|
|
|
|
|
|
|
|
expectEmit(result.source, factory, 'Incorrect factory');
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|