Skip to content

Commit 8d479c9

Browse files
alan-agius4alexeagle
authored andcommitted
test: add test to verify that the new es2015 class wrapping logic handles wrapping of tslib and tsickle classes
Related to ngrx/platform#1905 and ng-packagr/ng-packagr#1307 Fixes #14613
1 parent 8104fce commit 8d479c9

File tree

1 file changed

+32
-2
lines changed

1 file changed

+32
-2
lines changed

packages/angular_devkit/build_optimizer/src/transforms/wrap-enums_spec.ts

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,40 @@ import { getWrapEnumsTransformer } from './wrap-enums';
1414
const transform = (content: string) => transformJavascript(
1515
{ content, getTransforms: [getWrapEnumsTransformer] }).content;
1616

17-
// tslint:disable-next-line:no-big-function
17+
// tslint:disable:no-big-function
1818
describe('wrap enums and classes transformer', () => {
1919
describe('wraps class declarations', () => {
20+
it('should wrap tsickle emitted classes which followed by metadata', () => {
21+
const input = tags.stripIndent`
22+
class CustomComponentEffects {
23+
constructor(_actions) {
24+
this._actions = _actions;
25+
this.doThis = this._actions;
26+
}
27+
}
28+
CustomComponentEffects.decorators = [{ type: Injectable }];
29+
CustomComponentEffects.ctorParameters = () => [{ type: Actions }];
30+
tslib_1.__decorate([
31+
Effect(),
32+
tslib_1.__metadata("design:type", Object)
33+
], CustomComponentEffects.prototype, "doThis", void 0);
34+
tslib_1.__decorate([
35+
Effect({ dispatch: false }),
36+
tslib_1.__metadata("design:type", Object)
37+
], CustomComponentEffects.prototype, "doThat", void 0);
38+
`;
39+
40+
const output = tags.stripIndent`
41+
const CustomComponentEffects = /*@__PURE__*/ (() => {
42+
${input}
43+
44+
return CustomComponentEffects;
45+
})();
46+
`;
47+
48+
expect(tags.oneLine`${transform(input)}`).toEqual(tags.oneLine`${output}`);
49+
});
50+
2051
it('should ClassDeclarations that are referenced with in CallExpressions', () => {
2152
const input = tags.stripIndent`
2253
class ApplicationModule {
@@ -305,7 +336,6 @@ describe('wrap enums and classes transformer', () => {
305336
});
306337
});
307338

308-
// tslint:disable-next-line:no-big-function
309339
describe('wrap enums', () => {
310340
it('wraps ts 2.2 enums in IIFE', () => {
311341
const input = tags.stripIndent`

0 commit comments

Comments
 (0)