Skip to content

Commit bc0fa0c

Browse files
fix: opt-in to removing ng attributes
2 parents c59e545 + ca4b19e commit bc0fa0c

File tree

5 files changed

+42
-24
lines changed

5 files changed

+42
-24
lines changed

projects/testing-library/src/lib/models.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -266,14 +266,14 @@ export interface RenderComponentOptions<ComponentType, Q extends Queries = typeo
266266

267267
/**
268268
* @description
269-
* Removes the Angular attributes (ng-version, and id) from the fixture.
269+
* Removes the Angular attributes (ng-version, and root-id) from the fixture.
270270
*
271271
* @default
272-
* `true`
272+
* `false`
273273
*
274274
* @example
275275
* const component = await render(AppComponent, {
276-
* removeAngularAttributes: false
276+
* removeAngularAttributes: true
277277
* })
278278
*/
279279
removeAngularAttributes?: boolean;

projects/testing-library/src/lib/testing-library.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export async function render<SutType, WrapperType = SutType>(
4848
componentProviders = [],
4949
excludeComponentDeclaration = false,
5050
routes,
51-
removeAngularAttributes = true,
51+
removeAngularAttributes = false,
5252
} = renderOptions as RenderDirectiveOptions<SutType, WrapperType>;
5353

5454
TestBed.configureTestingModule({
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,43 @@
1-
import { Component } from '@angular/core';
1+
import { Component, Input } from '@angular/core';
22
import { render } from '../src/public_api';
33

44
@Component({
55
selector: 'fixture',
66
template: `
7-
Hello!
7+
Hello {{ name }}!
88
`,
99
})
10-
class FixtureComponent {}
10+
class FixtureComponent {
11+
@Input() name: string;
12+
}
1113

12-
test('first', async () => {
13-
await render(FixtureComponent);
14+
describe('Angular auto clean up - previous components only get cleanup up on init (based on root-id)', () => {
15+
test('first', async () => {
16+
await render(FixtureComponent, {
17+
componentProperties: {
18+
name: 'first',
19+
},
20+
});
21+
});
22+
23+
test('second', async () => {
24+
await render(FixtureComponent, {
25+
componentProperties: {
26+
name: 'second',
27+
},
28+
});
29+
expect(document.body.innerHTML).not.toContain('first');
30+
});
1431
});
1532

16-
test('second', () => {
17-
expect(document.body.innerHTML).toEqual('');
33+
describe('ATL auto clean up - after each test the containers get removed', () => {
34+
test('first', async () => {
35+
await render(FixtureComponent, {
36+
removeAngularAttributes: true,
37+
});
38+
});
39+
40+
test('second', () => {
41+
expect(document.body.innerHTML).toEqual('');
42+
});
1843
});

projects/testing-library/tests/directive.spec.ts

+2-11
Original file line numberDiff line numberDiff line change
@@ -78,29 +78,20 @@ test('overrides output properties', async () => {
7878
expect(clicked).toHaveBeenCalledWith('off');
7979
});
8080

81-
test('should remove angular attributes', async () => {
82-
await render(OnOffDirective, {
83-
template: '<div onOff (clicked)="clicked($event)"></div>',
84-
});
85-
86-
expect(document.querySelector('[ng-version]')).toBeNull();
87-
expect(document.querySelector('[id]')).toBeNull();
88-
});
89-
9081
describe('removeAngularAttributes', () => {
9182
test('should remove angular attributes', async () => {
9283
await render(OnOffDirective, {
9384
template: '<div onOff (clicked)="clicked($event)"></div>',
85+
removeAngularAttributes: true,
9486
});
9587

9688
expect(document.querySelector('[ng-version]')).toBeNull();
9789
expect(document.querySelector('[id]')).toBeNull();
9890
});
9991

100-
test('can be disabled', async () => {
92+
test('is disabled by default', async () => {
10193
await render(OnOffDirective, {
10294
template: '<div onOff (clicked)="clicked($event)"></div>',
103-
removeAngularAttributes: false,
10495
});
10596

10697
expect(document.querySelector('[ng-version]')).not.toBeNull();

projects/testing-library/tests/render.spec.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,15 @@ test('creates queries and events', async () => {
2222

2323
describe('removeAngularAttributes', () => {
2424
test('should remove angular attribute', async () => {
25-
await render(FixtureComponent);
25+
await render(FixtureComponent, {
26+
removeAngularAttributes: true,
27+
});
2628

2729
expect(document.querySelector('[ng-version]')).toBeNull();
2830
expect(document.querySelector('[id]')).toBeNull();
2931
});
3032

31-
test('can be disabled', async () => {
33+
test('is disabled by default', async () => {
3234
await render(FixtureComponent, {
3335
removeAngularAttributes: false,
3436
});

0 commit comments

Comments
 (0)