Skip to content

Commit 5a63a47

Browse files
devversionalxhub
authored andcommitted
test(compiler-cli): add unit tests for output() JIT transform (#54841)
We are already testing the JIT transforms via integration tests, but this commit adds dedicated unit tests for the transform behavior for proper test coverage (planned follow-up). PR Close #54841
1 parent c3da797 commit 5a63a47

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

packages/compiler-cli/test/initializer_api_transforms_spec.ts

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,61 @@ describe('initializer API metadata transform', () => {
375375
`));
376376
});
377377
});
378+
379+
describe('output()', () => {
380+
it('should insert an `@Output` decorator', () => {
381+
const result = transform(`
382+
import {output, Directive} from '@angular/core';
383+
384+
@Directive({})
385+
class MyDir {
386+
someInput = output();
387+
}
388+
`);
389+
390+
expect(result).toContain(omitLeadingWhitespace(`
391+
__decorate([
392+
i0.Output("someInput")
393+
], MyDir.prototype, "someInput", void 0);
394+
`));
395+
});
396+
397+
it('should insert an `@Output` decorator with aliases', () => {
398+
const result = transform(`
399+
import {output, Directive} from '@angular/core';
400+
401+
@Directive({})
402+
class MyDir {
403+
someInput = output({alias: 'someAlias'});
404+
}
405+
`);
406+
407+
expect(result).toContain(omitLeadingWhitespace(`
408+
__decorate([
409+
i0.Output("someAlias")
410+
], MyDir.prototype, "someInput", void 0);
411+
`));
412+
});
413+
414+
it('should not change an existing `@Output` decorator', () => {
415+
const result = transform(`
416+
import {output, Output, Directive} from '@angular/core';
417+
418+
const bla = 'some string';
419+
420+
@Directive({})
421+
class MyDir {
422+
@Output(bla) someInput = output({});
423+
}
424+
`);
425+
426+
expect(result).toContain(omitLeadingWhitespace(`
427+
__decorate([
428+
Output(bla)
429+
], MyDir.prototype, "someInput", void 0);
430+
`));
431+
});
432+
});
378433
});
379434

380435
/** Omits the leading whitespace for each line of the given text. */

0 commit comments

Comments
 (0)