Skip to content

test(material/button): refactor variable type to const in button component unit tests #22893

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
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
66 changes: 33 additions & 33 deletions src/material/button/button.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,27 +18,27 @@ describe('MatButton', () => {

// General button tests
it('should apply class based on color attribute', () => {
let fixture = TestBed.createComponent(TestApp);
const fixture = TestBed.createComponent(TestApp);

let testComponent = fixture.debugElement.componentInstance;
let buttonDebugElement = fixture.debugElement.query(By.css('button'))!;
let aDebugElement = fixture.debugElement.query(By.css('a'))!;
const testComponent = fixture.debugElement.componentInstance;
const buttonDebugElement = fixture.debugElement.query(By.css('button'))!;
const attributeDebugElement = fixture.debugElement.query(By.css('a'))!;

testComponent.buttonColor = 'primary';
fixture.detectChanges();
expect(buttonDebugElement.nativeElement.classList.contains('mat-primary')).toBe(true);
expect(aDebugElement.nativeElement.classList.contains('mat-primary')).toBe(true);
expect(attributeDebugElement.nativeElement.classList.contains('mat-primary')).toBe(true);

testComponent.buttonColor = 'accent';
fixture.detectChanges();
expect(buttonDebugElement.nativeElement.classList.contains('mat-accent')).toBe(true);
expect(aDebugElement.nativeElement.classList.contains('mat-accent')).toBe(true);
expect(attributeDebugElement.nativeElement.classList.contains('mat-accent')).toBe(true);

testComponent.buttonColor = null;
fixture.detectChanges();

expect(buttonDebugElement.nativeElement.classList).not.toContain('mat-accent');
expect(aDebugElement.nativeElement.classList).not.toContain('mat-accent');
expect(attributeDebugElement.nativeElement.classList).not.toContain('mat-accent');
});

it('should expose the ripple instance', () => {
Expand All @@ -50,9 +50,9 @@ describe('MatButton', () => {
});

it('should not clear previous defined classes', () => {
let fixture = TestBed.createComponent(TestApp);
let testComponent = fixture.debugElement.componentInstance;
let buttonDebugElement = fixture.debugElement.query(By.css('button'))!;
const fixture = TestBed.createComponent(TestApp);
const testComponent = fixture.debugElement.componentInstance;
const buttonDebugElement = fixture.debugElement.query(By.css('button'))!;

buttonDebugElement.nativeElement.classList.add('custom-class');

Expand Down Expand Up @@ -128,18 +128,18 @@ describe('MatButton', () => {
// Regular button tests
describe('button[mat-button]', () => {
it('should handle a click on the button', () => {
let fixture = TestBed.createComponent(TestApp);
let testComponent = fixture.debugElement.componentInstance;
let buttonDebugElement = fixture.debugElement.query(By.css('button'))!;
const fixture = TestBed.createComponent(TestApp);
const testComponent = fixture.debugElement.componentInstance;
const buttonDebugElement = fixture.debugElement.query(By.css('button'))!;

buttonDebugElement.nativeElement.click();
expect(testComponent.clickCount).toBe(1);
});

it('should not increment if disabled', () => {
let fixture = TestBed.createComponent(TestApp);
let testComponent = fixture.debugElement.componentInstance;
let buttonDebugElement = fixture.debugElement.query(By.css('button'))!;
const fixture = TestBed.createComponent(TestApp);
const testComponent = fixture.debugElement.componentInstance;
const buttonDebugElement = fixture.debugElement.query(By.css('button'))!;

testComponent.isDisabled = true;
fixture.detectChanges();
Expand All @@ -150,8 +150,8 @@ describe('MatButton', () => {
});

it('should disable the native button element', () => {
let fixture = TestBed.createComponent(TestApp);
let buttonNativeElement = fixture.nativeElement.querySelector('button');
const fixture = TestBed.createComponent(TestApp);
const buttonNativeElement = fixture.nativeElement.querySelector('button');
expect(buttonNativeElement.disabled).toBeFalsy('Expected button not to be disabled');

fixture.componentInstance.isDisabled = true;
Expand All @@ -164,9 +164,9 @@ describe('MatButton', () => {
// Anchor button tests
describe('a[mat-button]', () => {
it('should not redirect if disabled', () => {
let fixture = TestBed.createComponent(TestApp);
let testComponent = fixture.debugElement.componentInstance;
let buttonDebugElement = fixture.debugElement.query(By.css('a'))!;
const fixture = TestBed.createComponent(TestApp);
const testComponent = fixture.debugElement.componentInstance;
const buttonDebugElement = fixture.debugElement.query(By.css('a'))!;

testComponent.isDisabled = true;
fixture.detectChanges();
Expand All @@ -175,9 +175,9 @@ describe('MatButton', () => {
});

it('should remove tabindex if disabled', () => {
let fixture = TestBed.createComponent(TestApp);
let testComponent = fixture.debugElement.componentInstance;
let buttonDebugElement = fixture.debugElement.query(By.css('a'))!;
const fixture = TestBed.createComponent(TestApp);
const testComponent = fixture.debugElement.componentInstance;
const buttonDebugElement = fixture.debugElement.query(By.css('a'))!;
expect(buttonDebugElement.nativeElement.getAttribute('tabIndex')).toBe(null);

testComponent.isDisabled = true;
Expand All @@ -186,9 +186,9 @@ describe('MatButton', () => {
});

it('should add aria-disabled attribute if disabled', () => {
let fixture = TestBed.createComponent(TestApp);
let testComponent = fixture.debugElement.componentInstance;
let buttonDebugElement = fixture.debugElement.query(By.css('a'))!;
const fixture = TestBed.createComponent(TestApp);
const testComponent = fixture.debugElement.componentInstance;
const buttonDebugElement = fixture.debugElement.query(By.css('a'))!;
fixture.detectChanges();
expect(buttonDebugElement.nativeElement.getAttribute('aria-disabled')).toBe('false');

Expand All @@ -198,9 +198,9 @@ describe('MatButton', () => {
});

it('should not add aria-disabled attribute if disabled is false', () => {
let fixture = TestBed.createComponent(TestApp);
let testComponent = fixture.debugElement.componentInstance;
let buttonDebugElement = fixture.debugElement.query(By.css('a'))!;
const fixture = TestBed.createComponent(TestApp);
const testComponent = fixture.debugElement.componentInstance;
const buttonDebugElement = fixture.debugElement.query(By.css('a'))!;
fixture.detectChanges();
expect(buttonDebugElement.nativeElement.getAttribute('aria-disabled'))
.toBe('false', 'Expect aria-disabled="false"');
Expand All @@ -216,9 +216,9 @@ describe('MatButton', () => {
});

it('should be able to set a custom tabindex', () => {
let fixture = TestBed.createComponent(TestApp);
let testComponent = fixture.debugElement.componentInstance;
let buttonElement = fixture.debugElement.query(By.css('a'))!.nativeElement;
const fixture = TestBed.createComponent(TestApp);
const testComponent = fixture.debugElement.componentInstance;
const buttonElement = fixture.debugElement.query(By.css('a'))!.nativeElement;

fixture.componentInstance.tabIndex = 3;
fixture.detectChanges();
Expand Down