Skip to content

Commit 68d5a57

Browse files
clydinhansl
authored andcommitted
test: add custom decorator class removal test
1 parent 329b61c commit 68d5a57

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

packages/@ngtools/webpack/src/transformers/remove_decorators.spec.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,46 @@ describe('@ngtools/webpack transformers', () => {
124124
expect(oneLine`${result}`).toEqual(oneLine`${output}`);
125125
});
126126

127+
it('should keep other decorators on class declaration', () => {
128+
const input = stripIndent`
129+
import { Component } from '@angular/core';
130+
import { AnotherDecorator } from 'another-lib';
131+
132+
@AnotherDecorator()
133+
@Component({
134+
selector: 'app-root',
135+
templateUrl: './app.component.html',
136+
styleUrls: ['./app.component.css']
137+
})
138+
export class AppComponent {
139+
title = 'app';
140+
}
141+
`;
142+
const output = stripIndent`
143+
import * as tslib_1 from "tslib";
144+
import { AnotherDecorator } from 'another-lib';
145+
146+
let AppComponent = class AppComponent {
147+
constructor() {
148+
this.title = 'app';
149+
}
150+
};
151+
AppComponent = tslib_1.__decorate([
152+
AnotherDecorator()
153+
], AppComponent);
154+
export { AppComponent };
155+
`;
156+
157+
const { program, compilerHost } = createTypescriptContext(input);
158+
const transformer = removeDecorators(
159+
() => true,
160+
() => program.getTypeChecker(),
161+
);
162+
const result = transformTypescript(undefined, [transformer], program, compilerHost);
163+
164+
expect(oneLine`${result}`).toEqual(oneLine`${output}`);
165+
});
166+
127167
it('should remove imports for identifiers within the decorator', () => {
128168
const input = stripIndent`
129169
import { Component } from '@angular/core';

0 commit comments

Comments
 (0)