Skip to content

fix: opt in remove ng attributes #71

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions projects/testing-library/src/lib/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -266,14 +266,14 @@ export interface RenderComponentOptions<ComponentType, Q extends Queries = typeo

/**
* @description
* Removes the Angular attributes (ng-version, and id) from the fixture.
* Removes the Angular attributes (ng-version, and root-id) from the fixture.
*
* @default
* `true`
* `false`
*
* @example
* const component = await render(AppComponent, {
* removeAngularAttributes: false
* removeAngularAttributes: true
* })
*/
removeAngularAttributes?: boolean;
Expand Down
2 changes: 1 addition & 1 deletion projects/testing-library/src/lib/testing-library.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export async function render<SutType, WrapperType = SutType>(
componentProviders = [],
excludeComponentDeclaration = false,
routes,
removeAngularAttributes = true,
removeAngularAttributes = false,
} = renderOptions as RenderDirectiveOptions<SutType, WrapperType>;

TestBed.configureTestingModule({
Expand Down
39 changes: 32 additions & 7 deletions projects/testing-library/tests/auto-cleanup.spec.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,43 @@
import { Component } from '@angular/core';
import { Component, Input } from '@angular/core';
import { render } from '../src/public_api';

@Component({
selector: 'fixture',
template: `
Hello!
Hello {{ name }}!
`,
})
class FixtureComponent {}
class FixtureComponent {
@Input() name: string;
}

test('first', async () => {
await render(FixtureComponent);
describe('Angular auto clean up - previous components only get cleanup up on init (based on root-id)', () => {
test('first', async () => {
await render(FixtureComponent, {
componentProperties: {
name: 'first',
},
});
});

test('second', async () => {
await render(FixtureComponent, {
componentProperties: {
name: 'second',
},
});
expect(document.body.innerHTML).not.toContain('first');
});
});

test('second', () => {
expect(document.body.innerHTML).toEqual('');
describe('ATL auto clean up - after each test the containers get removed', () => {
test('first', async () => {
await render(FixtureComponent, {
removeAngularAttributes: true,
});
});

test('second', () => {
expect(document.body.innerHTML).toEqual('');
});
});
13 changes: 2 additions & 11 deletions projects/testing-library/tests/directive.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,29 +78,20 @@ test('overrides output properties', async () => {
expect(clicked).toHaveBeenCalledWith('off');
});

test('should remove angular attributes', async () => {
await render(OnOffDirective, {
template: '<div onOff (clicked)="clicked($event)"></div>',
});

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

describe('removeAngularAttributes', () => {
test('should remove angular attributes', async () => {
await render(OnOffDirective, {
template: '<div onOff (clicked)="clicked($event)"></div>',
removeAngularAttributes: true,
});

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

test('can be disabled', async () => {
test('is disabled by default', async () => {
await render(OnOffDirective, {
template: '<div onOff (clicked)="clicked($event)"></div>',
removeAngularAttributes: false,
});

expect(document.querySelector('[ng-version]')).not.toBeNull();
Expand Down
6 changes: 4 additions & 2 deletions projects/testing-library/tests/render.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,15 @@ test('creates queries and events', async () => {

describe('removeAngularAttributes', () => {
test('should remove angular attribute', async () => {
await render(FixtureComponent);
await render(FixtureComponent, {
removeAngularAttributes: true,
});

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

test('can be disabled', async () => {
test('is disabled by default', async () => {
await render(FixtureComponent, {
removeAngularAttributes: false,
});
Expand Down