@@ -19,6 +19,30 @@ function transform(input: string, additionalFiles?: Record<string, string>) {
19
19
20
20
describe ( 'Constructor Parameter Transformer' , ( ) => {
21
21
it ( 'records class name in same module' , ( ) => {
22
+ const input = `
23
+ export class ClassInject {};
24
+
25
+ @Injectable()
26
+ export class MyService {
27
+ constructor(v: ClassInject) {}
28
+ }
29
+ ` ;
30
+
31
+ const output = `
32
+ import * as tslib_1 from "tslib";
33
+ export class ClassInject { } ;
34
+ let MyService = class MyService { constructor(v) { } };
35
+ MyService.ctorParameters = () => [ { type: ClassInject } ];
36
+ MyService = tslib_1.__decorate([ Injectable() ], MyService);
37
+ export { MyService };
38
+ ` ;
39
+
40
+ const result = transform ( input ) ;
41
+
42
+ expect ( tags . oneLine `${ result } ` ) . toEqual ( tags . oneLine `${ output } ` ) ;
43
+ } ) ;
44
+
45
+ it ( 'does not record when class does not have a decorator' , ( ) => {
22
46
const input = `
23
47
export class ClassInject {};
24
48
@@ -29,7 +53,7 @@ describe('Constructor Parameter Transformer', () => {
29
53
30
54
const output = `
31
55
export class ClassInject { } ;
32
- export class MyService { constructor(v) { } } MyService.ctorParameters = () => [ { type: ClassInject } ];
56
+ export class MyService { constructor(v) { } }
33
57
` ;
34
58
35
59
const result = transform ( input ) ;
@@ -47,19 +71,22 @@ describe('Constructor Parameter Transformer', () => {
47
71
constructor() { }
48
72
}
49
73
74
+ @Injectable()
50
75
export class MyService {
51
76
constructor(v: RootProvidedService) {}
52
77
}
53
78
` ;
54
79
55
- // tslint:disable:max-line-length
56
80
const output = `
57
81
import * as tslib_1 from "tslib";
58
82
let RootProvidedService = class RootProvidedService { constructor() { } };
59
83
RootProvidedService = tslib_1.__decorate([ Injectable({ providedIn: 'root' }) ], RootProvidedService);
60
- export { RootProvidedService }; export class MyService { constructor(v) { } } MyService.ctorParameters = () => [ { type: RootProvidedService } ];
84
+ export { RootProvidedService };
85
+ let MyService = class MyService { constructor(v) { } };
86
+ MyService.ctorParameters = () => [ { type: RootProvidedService } ];
87
+ MyService = tslib_1.__decorate([ Injectable() ], MyService);
88
+ export { MyService };
61
89
` ;
62
- // tslint:enable:max-line-length
63
90
64
91
const result = transform ( input ) ;
65
92
@@ -84,6 +111,7 @@ describe('Constructor Parameter Transformer', () => {
84
111
const input = `
85
112
import { RootProvidedService } from './root-provided-service';
86
113
114
+ @Injectable()
87
115
export class MyService {
88
116
constructor(v: RootProvidedService) {}
89
117
}
@@ -101,6 +129,7 @@ describe('Constructor Parameter Transformer', () => {
101
129
export interface InterInject {}
102
130
export const INTERFACE_INJECT = new InjectionToken<InterInject>('interface-inject');
103
131
132
+ @Injectable()
104
133
export class MyService {
105
134
constructor(@Inject(INTERFACE_INJECT) v: InterInject) {}
106
135
}
@@ -111,7 +140,7 @@ describe('Constructor Parameter Transformer', () => {
111
140
export const INTERFACE_INJECT = new InjectionToken('interface-inject');
112
141
let MyService = class MyService { constructor(v) { } };
113
142
MyService.ctorParameters = () => [ { type: undefined, decorators: [{ type: Inject, args: [INTERFACE_INJECT,] }] } ];
114
- MyService = tslib_1.__decorate([ tslib_1.__param(0, Inject(INTERFACE_INJECT)) ], MyService);
143
+ MyService = tslib_1.__decorate([ Injectable(), tslib_1.__param(0, Inject(INTERFACE_INJECT)) ], MyService);
115
144
export { MyService };
116
145
` ;
117
146
@@ -125,6 +154,7 @@ describe('Constructor Parameter Transformer', () => {
125
154
interface InterInject {}
126
155
export const INTERFACE_INJECT = new InjectionToken<InterInject>('interface-inject');
127
156
157
+ @Injectable()
128
158
export class MyService {
129
159
constructor(@Inject(INTERFACE_INJECT) v: InterInject) {}
130
160
}
@@ -135,7 +165,7 @@ describe('Constructor Parameter Transformer', () => {
135
165
export const INTERFACE_INJECT = new InjectionToken('interface-inject');
136
166
let MyService = class MyService { constructor(v) { } };
137
167
MyService.ctorParameters = () => [ { type: undefined, decorators: [{ type: Inject, args: [INTERFACE_INJECT,] }] } ];
138
- MyService = tslib_1.__decorate([ tslib_1.__param(0, Inject(INTERFACE_INJECT)) ], MyService);
168
+ MyService = tslib_1.__decorate([ Injectable(), tslib_1.__param(0, Inject(INTERFACE_INJECT)) ], MyService);
139
169
export { MyService };
140
170
` ;
141
171
@@ -155,6 +185,7 @@ describe('Constructor Parameter Transformer', () => {
155
185
const input = `
156
186
import { INTERFACE_INJECT, InterInject } from './module-inject';
157
187
188
+ @Injectable()
158
189
export class MyService {
159
190
constructor(@Inject(INTERFACE_INJECT) v: InterInject) {}
160
191
}
@@ -165,7 +196,7 @@ describe('Constructor Parameter Transformer', () => {
165
196
import { INTERFACE_INJECT } from './module-inject';
166
197
let MyService = class MyService { constructor(v) { } };
167
198
MyService.ctorParameters = () => [ { type: undefined, decorators: [{ type: Inject, args: [INTERFACE_INJECT,] }] } ];
168
- MyService = tslib_1.__decorate([ tslib_1.__param(0, Inject(INTERFACE_INJECT)) ], MyService);
199
+ MyService = tslib_1.__decorate([ Injectable(), tslib_1.__param(0, Inject(INTERFACE_INJECT)) ], MyService);
169
200
export { MyService };
170
201
` ;
171
202
0 commit comments