diff --git a/src/cdk-experimental/dialog/dialog.spec.ts b/src/cdk-experimental/dialog/dialog.spec.ts
index 1dbdd33187cd..1fa959416871 100644
--- a/src/cdk-experimental/dialog/dialog.spec.ts
+++ b/src/cdk-experimental/dialog/dialog.spec.ts
@@ -209,8 +209,8 @@ describe('Dialog', () => {
// beforeClose should emit before dialog container is destroyed
const beforeCloseHandler = jasmine.createSpy('beforeClose callback').and.callFake(() => {
- expect(overlayContainerElement.querySelector('cdk-dialog-container'))
- .not.toBeNull('dialog container exists when beforeClose is called');
+ expect(overlayContainerElement.querySelector('cdk-dialog-container')).not
+ .withContext('dialog container exists when beforeClose is called').toBeNull();
});
dialogRef.beforeClosed().subscribe(beforeCloseHandler);
@@ -261,7 +261,7 @@ describe('Dialog', () => {
flushMicrotasks();
expect(overlayContainerElement.querySelectorAll('cdk-dialog-container').length)
- .toBe(1, 'Expected one open dialog.');
+ .withContext('Expected one open dialog.').toBe(1);
dialogRef.close();
flushMicrotasks();
@@ -269,7 +269,7 @@ describe('Dialog', () => {
tick(500);
expect(overlayContainerElement.querySelectorAll('cdk-dialog-container').length)
- .toBe(0, 'Expected no open dialogs.');
+ .withContext('Expected no open dialogs.').toBe(0);
}));
it('should close when clicking on the overlay backdrop', fakeAsync(() => {
@@ -403,8 +403,8 @@ describe('Dialog', () => {
let overlayPane = overlayContainerElement.querySelector('.cdk-overlay-pane') as HTMLElement;
- expect(overlayPane.style.maxWidth).toBe('80vw',
- 'Expected dialog to set a default max-width on overlay pane');
+ expect(overlayPane.style.maxWidth)
+ .withContext('Expected dialog to set a default max-width on overlay pane').toBe('80vw');
dialogRef.close();
@@ -716,7 +716,8 @@ describe('Dialog', () => {
viewContainerFixture.detectChanges();
flush();
- expect(dialogRef.componentInstance).toBeFalsy('Expected reference to have been cleared.');
+ expect(dialogRef.componentInstance)
+ .withContext('Expected reference to have been cleared.').toBeFalsy();
}));
it('should assign a unique id to each dialog', () => {
@@ -892,7 +893,8 @@ describe('Dialog', () => {
flushMicrotasks();
expect(document.activeElement!.tagName)
- .toBe('INPUT', 'Expected first tabbable element (input) in the dialog to be focused.');
+ .withContext('Expected first tabbable element (input) in the dialog to be focused.')
+ .toBe('INPUT');
}));
it('should focus the dialog element on open', fakeAsync(() => {
@@ -907,7 +909,8 @@ describe('Dialog', () => {
let container =
overlayContainerElement.querySelector('cdk-dialog-container') as HTMLInputElement;
- expect(document.activeElement).toBe(container, 'Expected container to be focused on open');
+ expect(document.activeElement)
+ .withContext('Expected container to be focused on open').toBe(container);
}));
it('should focus the first header element on open', fakeAsync(() => {
@@ -923,7 +926,7 @@ describe('Dialog', () => {
overlayContainerElement.querySelector('h1[tabindex="-1"]') as HTMLInputElement;
expect(document.activeElement)
- .toBe(firstHeader, 'Expected first header to be focused on open');
+ .withContext('Expected first header to be focused on open').toBe(firstHeader);
}));
it('should focus the first element that matches the css selector from autoFocus on open',
@@ -940,7 +943,7 @@ describe('Dialog', () => {
overlayContainerElement.querySelector('p[tabindex="-1"]') as HTMLInputElement;
expect(document.activeElement)
- .toBe(firstParagraph, 'Expected first paragraph to be focused on open');
+ .withContext('Expected first paragraph to be focused on open').toBe(firstParagraph);
}));
it('should re-focus trigger element when dialog closes', fakeAsync(() => {
@@ -968,8 +971,9 @@ describe('Dialog', () => {
viewContainerFixture.detectChanges();
flush();
- expect(document.activeElement!.id).toBe('dialog-trigger',
- 'Expected that the trigger was refocused after the dialog is closed.');
+ expect(document.activeElement!.id)
+ .withContext('Expected that the trigger was refocused after the dialog is closed.')
+ .toBe('dialog-trigger');
document.body.removeChild(button);
}));
@@ -1027,14 +1031,14 @@ describe('Dialog', () => {
otherButton.focus();
expect(document.activeElement!.id)
- .toBe('other-button', 'Expected focus to be on the alternate button.');
+ .withContext('Expected focus to be on the alternate button.').toBe('other-button');
flushMicrotasks();
viewContainerFixture.detectChanges();
flush();
expect(document.activeElement!.id)
- .toBe('other-button', 'Expected focus to stay on the alternate button.');
+ .withContext('Expected focus to stay on the alternate button.').toBe('other-button');
body.removeChild(button);
body.removeChild(otherButton);
@@ -1065,8 +1069,9 @@ describe('Dialog', () => {
viewContainerFixture.detectChanges();
flushMicrotasks();
- expect(document.activeElement!.id).toBe('input-to-be-focused',
- 'Expected that the trigger was refocused after the dialog is closed.');
+ expect(document.activeElement!.id)
+ .withContext('Expected that the trigger was refocused after the dialog is closed.')
+ .toBe('input-to-be-focused');
document.body.removeChild(button);
document.body.removeChild(input);
@@ -1081,7 +1086,7 @@ describe('Dialog', () => {
flushMicrotasks();
expect(document.activeElement!.tagName.toLowerCase())
- .toBe('cdk-dialog-container', 'Expected dialog container to be focused.');
+ .withContext('Expected dialog container to be focused.').toBe('cdk-dialog-container');
}));
});
@@ -1154,14 +1159,14 @@ describe('Dialog with a parent Dialog', () => {
flush();
expect(overlayContainerElement.textContent)
- .toContain('Pizza', 'Expected a dialog to be opened');
+ .withContext('Expected a dialog to be opened').toContain('Pizza');
childDialog.closeAll();
fixture.detectChanges();
flush();
expect(overlayContainerElement.textContent!.trim())
- .toBe('', 'Expected closeAll on child Dialog to close dialog opened by parent');
+ .withContext('Expected closeAll on child Dialog to close dialog opened by parent').toBe('');
}));
it('should close dialogs opened by a child when calling closeAll on a parent Dialog',
@@ -1170,14 +1175,14 @@ describe('Dialog with a parent Dialog', () => {
fixture.detectChanges();
expect(overlayContainerElement.textContent)
- .toContain('Pizza', 'Expected a dialog to be opened');
+ .withContext('Expected a dialog to be opened').toContain('Pizza');
parentDialog.closeAll();
fixture.detectChanges();
flush();
expect(overlayContainerElement.textContent!.trim())
- .toBe('', 'Expected closeAll on parent Dialog to close dialog opened by child');
+ .withContext('Expected closeAll on parent Dialog to close dialog opened by child').toBe('');
}));
it('should not close the parent dialogs, when a child is destroyed', fakeAsync(() => {
@@ -1186,14 +1191,14 @@ describe('Dialog with a parent Dialog', () => {
flush();
expect(overlayContainerElement.textContent)
- .toContain('Pizza', 'Expected a dialog to be opened');
+ .withContext('Expected a dialog to be opened').toContain('Pizza');
childDialog.ngOnDestroy();
fixture.detectChanges();
flush();
expect(overlayContainerElement.textContent)
- .toContain('Pizza', 'Expected a dialog to remain opened');
+ .withContext('Expected a dialog to remain opened').toContain('Pizza');
}));
it('should close the top dialog via the escape key', fakeAsync(() => {
diff --git a/src/cdk-experimental/listbox/listbox.spec.ts b/src/cdk-experimental/listbox/listbox.spec.ts
index c5a6b450d4a5..a47f1b81bc44 100644
--- a/src/cdk-experimental/listbox/listbox.spec.ts
+++ b/src/cdk-experimental/listbox/listbox.spec.ts
@@ -620,15 +620,15 @@ describe('CdkOption and CdkListbox', () => {
it('should be able to set the disabled state via setDisabledState', () => {
expect(listboxInstance.disabled)
- .toBe(false, 'Expected the selection list to be enabled.');
+ .withContext('Expected the selection list to be enabled.').toBe(false);
expect(optionInstances.every(option => !option.disabled))
- .toBe(true, 'Expected every list option to be enabled.');
+ .withContext('Expected every list option to be enabled.').toBe(true);
listboxInstance.setDisabledState(true);
fixture.detectChanges();
expect(listboxInstance.disabled)
- .toBe(true, 'Expected the selection list to be disabled.');
+ .withContext('Expected the selection list to be disabled.').toBe(true);
for (const option of optionElements) {
expect(option.getAttribute('aria-disabled')).toBe('true');
}
@@ -636,7 +636,7 @@ describe('CdkOption and CdkListbox', () => {
it('should be able to select options via writeValue', () => {
expect(optionInstances.every(option => !option.disabled))
- .toBe(true, 'Expected every list option to be enabled.');
+ .withContext('Expected every list option to be enabled.').toBe(true);
listboxInstance.writeValue('arc');
fixture.detectChanges();
@@ -651,7 +651,7 @@ describe('CdkOption and CdkListbox', () => {
it('should be select multiple options by their values', () => {
expect(optionInstances.every(option => !option.disabled))
- .toBe(true, 'Expected every list option to be enabled.');
+ .withContext('Expected every list option to be enabled.').toBe(true);
testComponent.isMultiselectable = true;
fixture.detectChanges();
@@ -676,7 +676,7 @@ describe('CdkOption and CdkListbox', () => {
it('should be able to disable options from the control', () => {
expect(testComponent.listbox.disabled).toBeFalse();
expect(optionInstances.every(option => !option.disabled))
- .toBe(true, 'Expected every list option to be enabled.');
+ .withContext('Expected every list option to be enabled.').toBe(true);
testComponent.form.disable();
fixture.detectChanges();
@@ -690,7 +690,7 @@ describe('CdkOption and CdkListbox', () => {
it('should be able to toggle disabled state after form control is disabled', () => {
expect(testComponent.listbox.disabled).toBeFalse();
expect(optionInstances.every(option => !option.disabled))
- .toBe(true, 'Expected every list option to be enabled.');
+ .withContext('Expected every list option to be enabled.').toBe(true);
testComponent.form.disable();
fixture.detectChanges();
@@ -705,7 +705,7 @@ describe('CdkOption and CdkListbox', () => {
expect(testComponent.listbox.disabled).toBeFalse();
expect(optionInstances.every(option => !option.disabled))
- .toBe(true, 'Expected every list option to be enabled.');
+ .withContext('Expected every list option to be enabled.').toBe(true);
});
it('should be able to select options via setting the value in form control', () => {
diff --git a/src/cdk-experimental/scrolling/virtual-scroll-viewport.spec.ts b/src/cdk-experimental/scrolling/virtual-scroll-viewport.spec.ts
index 946c7e05a32e..12c5aa05892e 100644
--- a/src/cdk-experimental/scrolling/virtual-scroll-viewport.spec.ts
+++ b/src/cdk-experimental/scrolling/virtual-scroll-viewport.spec.ts
@@ -29,7 +29,7 @@ describe('CdkVirtualScrollViewport', () => {
const contentWrapper =
viewport.elementRef.nativeElement.querySelector('.cdk-virtual-scroll-content-wrapper')!;
expect(contentWrapper.children.length)
- .toBe(4, 'should render 4 50px items to fill 200px space');
+ .withContext('should render 4 50px items to fill 200px space').toBe(4);
}));
it('should render extra content if first item is smaller than average', fakeAsync(() => {
@@ -38,8 +38,9 @@ describe('CdkVirtualScrollViewport', () => {
const contentWrapper =
viewport.elementRef.nativeElement.querySelector('.cdk-virtual-scroll-content-wrapper')!;
- expect(contentWrapper.children.length).toBe(4,
- 'should render 4 items to fill 200px space based on 50px estimate from first item');
+ expect(contentWrapper.children.length)
+ .withContext('should render 4 items to fill 200px space based on 50px ' +
+ 'estimate from first item').toBe(4);
}));
it('should throw if maxBufferPx is less than minBufferPx', fakeAsync(() => {
diff --git a/src/cdk/a11y/aria-describer/aria-describer.spec.ts b/src/cdk/a11y/aria-describer/aria-describer.spec.ts
index 03b5920c054c..d146a481d90e 100644
--- a/src/cdk/a11y/aria-describer/aria-describer.spec.ts
+++ b/src/cdk/a11y/aria-describer/aria-describer.spec.ts
@@ -128,19 +128,23 @@ describe('AriaDescriber', () => {
const descriptionNode = fixture.nativeElement.querySelector('#description-with-existing-id');
expect(document.body.contains(descriptionNode))
- .toBe(true, 'Expected node to be inside the document to begin with.');
- expect(getMessagesContainer()).toBeNull('Expected no messages container on init.');
+ .withContext('Expected node to be inside the document to begin with.')
+ .toBe(true);
+ expect(getMessagesContainer())
+ .withContext('Expected no messages container on init.').toBeNull();
ariaDescriber.describe(component.element1, descriptionNode);
expectMessage(component.element1, 'Hello');
expect(getMessagesContainer())
- .toBeNull('Expected no messages container after the element was described.');
+ .withContext('Expected no messages container after the element was described.')
+ .toBeNull();
ariaDescriber.removeDescription(component.element1, descriptionNode);
- expect(document.body.contains(descriptionNode)).toBe(true,
- 'Expected description node to still be in the DOM after it is no longer being used.');
+ expect(document.body.contains(descriptionNode))
+ .withContext('Expected description node to still be in the DOM after it is' +
+ 'no longer being used.').toBe(true);
});
it('should keep nodes set as descriptions inside their original position in the DOM', () => {
@@ -148,18 +152,20 @@ describe('AriaDescriber', () => {
const descriptionNode = fixture.nativeElement.querySelector('#description-with-existing-id');
const initialParent = descriptionNode.parentNode;
- expect(initialParent).toBeTruthy('Expected node to have a parent initially.');
+ expect(initialParent).withContext('Expected node to have a parent initially.').toBeTruthy();
ariaDescriber.describe(component.element1, descriptionNode);
expectMessage(component.element1, 'Hello');
- expect(descriptionNode.parentNode).toBe(initialParent,
- 'Expected node to stay inside the same parent when used as a description.');
+ expect(descriptionNode.parentNode)
+ .withContext('Expected node to stay inside the same parent when used as a description.')
+ .toBe(initialParent);
ariaDescriber.removeDescription(component.element1, descriptionNode);
- expect(descriptionNode.parentNode).toBe(initialParent,
- 'Expected node to stay inside the same parent after not being used as a description.');
+ expect(descriptionNode.parentNode)
+ .withContext('Expected node to stay inside the same parent after not ' +
+ 'being used as a description.').toBe(initialParent);
});
it('should be able to unregister messages while having others registered', () => {
@@ -247,7 +253,8 @@ describe('AriaDescriber', () => {
const descriptionNode = fixture.nativeElement.querySelector('#description-with-existing-id');
expect(document.body.contains(descriptionNode))
- .toBe(true, 'Expected node to be inside the document to begin with.');
+ .withContext('Expected node to be inside the document to begin with.')
+ .toBe(true);
ariaDescriber.describe(component.element1, descriptionNode);
@@ -257,8 +264,9 @@ describe('AriaDescriber', () => {
ariaDescriber.ngOnDestroy();
expect(component.element1.hasAttribute(CDK_DESCRIBEDBY_HOST_ATTRIBUTE)).toBe(false);
- expect(document.body.contains(descriptionNode)).toBe(true,
- 'Expected description node to still be in the DOM after it is no longer being used.');
+ expect(document.body.contains(descriptionNode))
+ .withContext('Expected description node to still be in the DOM after ' +
+ 'it is no longer being used.').toBe(true);
});
it('should remove the aria-describedby attribute if there are no more messages', () => {
diff --git a/src/cdk/a11y/focus-monitor/focus-monitor.spec.ts b/src/cdk/a11y/focus-monitor/focus-monitor.spec.ts
index 4292a4d78009..f21cbd31a870 100644
--- a/src/cdk/a11y/focus-monitor/focus-monitor.spec.ts
+++ b/src/cdk/a11y/focus-monitor/focus-monitor.spec.ts
@@ -80,7 +80,7 @@ describe('FocusMonitor', () => {
tick();
expect(buttonElement.classList.contains('cdk-focused'))
- .toBe(true, 'button should have cdk-focused class');
+ .withContext('button should have cdk-focused class').toBe(true);
expect(changeHandler).toHaveBeenCalledTimes(1);
}));
@@ -92,11 +92,11 @@ describe('FocusMonitor', () => {
flush();
expect(buttonElement.classList.length)
- .toBe(2, 'button should have exactly 2 focus classes');
+ .withContext('button should have exactly 2 focus classes').toBe(2);
expect(buttonElement.classList.contains('cdk-focused'))
- .toBe(true, 'button should have cdk-focused class');
+ .withContext('button should have cdk-focused class').toBe(true);
expect(buttonElement.classList.contains('cdk-keyboard-focused'))
- .toBe(true, 'button should have cdk-keyboard-focused class');
+ .withContext('button should have cdk-keyboard-focused class').toBe(true);
expect(changeHandler).toHaveBeenCalledWith('keyboard');
}));
@@ -108,11 +108,11 @@ describe('FocusMonitor', () => {
flush();
expect(buttonElement.classList.length)
- .toBe(2, 'button should have exactly 2 focus classes');
+ .withContext('button should have exactly 2 focus classes').toBe(2);
expect(buttonElement.classList.contains('cdk-focused'))
- .toBe(true, 'button should have cdk-focused class');
+ .withContext('button should have cdk-focused class').toBe(true);
expect(buttonElement.classList.contains('cdk-mouse-focused'))
- .toBe(true, 'button should have cdk-mouse-focused class');
+ .withContext('button should have cdk-mouse-focused class').toBe(true);
expect(changeHandler).toHaveBeenCalledWith('mouse');
}));
@@ -124,11 +124,11 @@ describe('FocusMonitor', () => {
tick(TOUCH_BUFFER_MS);
expect(buttonElement.classList.length)
- .toBe(2, 'button should have exactly 2 focus classes');
+ .withContext('button should have exactly 2 focus classes').toBe(2);
expect(buttonElement.classList.contains('cdk-focused'))
- .toBe(true, 'button should have cdk-focused class');
+ .withContext('button should have cdk-focused class').toBe(true);
expect(buttonElement.classList.contains('cdk-touch-focused'))
- .toBe(true, 'button should have cdk-touch-focused class');
+ .withContext('button should have cdk-touch-focused class').toBe(true);
expect(changeHandler).toHaveBeenCalledWith('touch');
}));
@@ -139,11 +139,11 @@ describe('FocusMonitor', () => {
tick();
expect(buttonElement.classList.length)
- .toBe(2, 'button should have exactly 2 focus classes');
+ .withContext('button should have exactly 2 focus classes').toBe(2);
expect(buttonElement.classList.contains('cdk-focused'))
- .toBe(true, 'button should have cdk-focused class');
+ .withContext('button should have cdk-focused class').toBe(true);
expect(buttonElement.classList.contains('cdk-program-focused'))
- .toBe(true, 'button should have cdk-program-focused class');
+ .withContext('button should have cdk-program-focused class').toBe(true);
expect(changeHandler).toHaveBeenCalledWith('program');
}));
@@ -159,11 +159,11 @@ describe('FocusMonitor', () => {
flush();
expect(buttonElement.classList.length)
- .toBe(2, 'button should have exactly 2 focus classes');
+ .withContext('button should have exactly 2 focus classes').toBe(2);
expect(buttonElement.classList.contains('cdk-focused'))
- .toBe(true, 'button should have cdk-focused class');
+ .withContext('button should have cdk-focused class').toBe(true);
expect(buttonElement.classList.contains('cdk-keyboard-focused'))
- .toBe(true, 'button should have cdk-keyboard-focused class');
+ .withContext('button should have cdk-keyboard-focused class').toBe(true);
expect(changeHandler).toHaveBeenCalledWith('keyboard');
}));
@@ -172,11 +172,11 @@ describe('FocusMonitor', () => {
flush();
expect(buttonElement.classList.length)
- .toBe(2, 'button should have exactly 2 focus classes');
+ .withContext('button should have exactly 2 focus classes').toBe(2);
expect(buttonElement.classList.contains('cdk-focused'))
- .toBe(true, 'button should have cdk-focused class');
+ .withContext('button should have cdk-focused class').toBe(true);
expect(buttonElement.classList.contains('cdk-keyboard-focused'))
- .toBe(true, 'button should have cdk-keyboard-focused class');
+ .withContext('button should have cdk-keyboard-focused class').toBe(true);
expect(changeHandler).toHaveBeenCalledWith('keyboard');
}));
@@ -186,11 +186,11 @@ describe('FocusMonitor', () => {
flush();
expect(buttonElement.classList.length)
- .toBe(2, 'button should have exactly 2 focus classes');
+ .withContext('button should have exactly 2 focus classes').toBe(2);
expect(buttonElement.classList.contains('cdk-focused'))
- .toBe(true, 'button should have cdk-focused class');
+ .withContext('button should have cdk-focused class').toBe(true);
expect(buttonElement.classList.contains('cdk-mouse-focused'))
- .toBe(true, 'button should have cdk-mouse-focused class');
+ .withContext('button should have cdk-mouse-focused class').toBe(true);
expect(changeHandler).toHaveBeenCalledWith('mouse');
}));
@@ -200,11 +200,11 @@ describe('FocusMonitor', () => {
flush();
expect(buttonElement.classList.length)
- .toBe(2, 'button should have exactly 2 focus classes');
+ .withContext('button should have exactly 2 focus classes').toBe(2);
expect(buttonElement.classList.contains('cdk-focused'))
- .toBe(true, 'button should have cdk-focused class');
+ .withContext('button should have cdk-focused class').toBe(true);
expect(buttonElement.classList.contains('cdk-touch-focused'))
- .toBe(true, 'button should have cdk-touch-focused class');
+ .withContext('button should have cdk-touch-focused class').toBe(true);
expect(changeHandler).toHaveBeenCalledWith('touch');
}));
@@ -214,11 +214,11 @@ describe('FocusMonitor', () => {
flush();
expect(buttonElement.classList.length)
- .toBe(2, 'button should have exactly 2 focus classes');
+ .withContext('button should have exactly 2 focus classes').toBe(2);
expect(buttonElement.classList.contains('cdk-focused'))
- .toBe(true, 'button should have cdk-focused class');
+ .withContext('button should have cdk-focused class').toBe(true);
expect(buttonElement.classList.contains('cdk-program-focused'))
- .toBe(true, 'button should have cdk-program-focused class');
+ .withContext('button should have cdk-program-focused class').toBe(true);
expect(changeHandler).toHaveBeenCalledWith('program');
}));
@@ -228,7 +228,7 @@ describe('FocusMonitor', () => {
tick();
expect(buttonElement.classList.length)
- .toBe(2, 'button should have exactly 2 focus classes');
+ .withContext('button should have exactly 2 focus classes').toBe(2);
expect(changeHandler).toHaveBeenCalledWith('program');
// Call `blur` directly because invoking `buttonElement.blur()` does not always trigger the
@@ -237,7 +237,7 @@ describe('FocusMonitor', () => {
fixture.detectChanges();
expect(buttonElement.classList.length)
- .toBe(0, 'button should not have any focus classes');
+ .withContext('button should not have any focus classes').toBe(0);
expect(changeHandler).toHaveBeenCalledWith(null);
}));
@@ -246,12 +246,18 @@ describe('FocusMonitor', () => {
fixture.detectChanges();
tick();
- expect(buttonElement.classList.length).toBe(2, 'button should have exactly 2 focus classes');
+ expect(buttonElement.classList.length)
+
+ .withContext('button should have exactly 2 focus classes')
+ .toBe(2);
focusMonitor.stopMonitoring(buttonElement);
fixture.detectChanges();
- expect(buttonElement.classList.length).toBe(0, 'button should not have any focus classes');
+ expect(buttonElement.classList.length)
+
+ .withContext('button should not have any focus classes')
+ .toBe(0);
}));
it('should remove classes when destroyed', fakeAsync(() => {
@@ -259,13 +265,19 @@ describe('FocusMonitor', () => {
fixture.detectChanges();
tick();
- expect(buttonElement.classList.length).toBe(2, 'button should have exactly 2 focus classes');
+ expect(buttonElement.classList.length)
+
+ .withContext('button should have exactly 2 focus classes')
+ .toBe(2);
// Destroy manually since destroying the fixture won't do it.
focusMonitor.ngOnDestroy();
fixture.detectChanges();
- expect(buttonElement.classList.length).toBe(0, 'button should not have any focus classes');
+ expect(buttonElement.classList.length)
+
+ .withContext('button should not have any focus classes')
+ .toBe(0);
}));
it('should pass focus options to the native focus method', fakeAsync(() => {
@@ -328,11 +340,11 @@ describe('FocusMonitor', () => {
fakeActiveElement = buttonElement;
expect(buttonElement.classList.length)
- .toBe(2, 'button should have exactly 2 focus classes');
+ .withContext('button should have exactly 2 focus classes').toBe(2);
expect(buttonElement.classList.contains('cdk-focused'))
- .toBe(true, 'button should have cdk-focused class');
+ .withContext('button should have cdk-focused class').toBe(true);
expect(buttonElement.classList.contains('cdk-keyboard-focused'))
- .toBe(true, 'button should have cdk-keyboard-focused class');
+ .withContext('button should have cdk-keyboard-focused class').toBe(true);
expect(changeHandler).toHaveBeenCalledTimes(1);
expect(changeHandler).toHaveBeenCalledWith('keyboard');
expect(buttonElement.focus).toHaveBeenCalledTimes(1);
@@ -342,11 +354,11 @@ describe('FocusMonitor', () => {
fakeActiveElement = buttonElement;
expect(buttonElement.classList.length)
- .toBe(2, 'button should have exactly 2 focus classes');
+ .withContext('button should have exactly 2 focus classes').toBe(2);
expect(buttonElement.classList.contains('cdk-focused'))
- .toBe(true, 'button should have cdk-focused class');
+ .withContext('button should have cdk-focused class').toBe(true);
expect(buttonElement.classList.contains('cdk-mouse-focused'))
- .toBe(true, 'button should have cdk-mouse-focused class');
+ .withContext('button should have cdk-mouse-focused class').toBe(true);
expect(changeHandler).toHaveBeenCalledTimes(2);
expect(changeHandler).toHaveBeenCalledWith('mouse');
expect(buttonElement.focus).toHaveBeenCalledTimes(1);
@@ -362,11 +374,11 @@ describe('FocusMonitor', () => {
fakeActiveElement = buttonElement;
expect(parent.classList.length)
- .toBe(3, 'Parent should have exactly 2 focus classes and the `parent` class');
+ .withContext('Parent should have exactly 2 focus classes and the `parent` class').toBe(3);
expect(parent.classList.contains('cdk-focused'))
- .toBe(true, 'Parent should have cdk-focused class');
+ .withContext('Parent should have cdk-focused class').toBe(true);
expect(parent.classList.contains('cdk-keyboard-focused'))
- .toBe(true, 'Parent should have cdk-keyboard-focused class');
+ .withContext('Parent should have cdk-keyboard-focused class').toBe(true);
expect(changeHandler).toHaveBeenCalledTimes(1);
expect(changeHandler).toHaveBeenCalledWith('keyboard');
expect(buttonElement.focus).toHaveBeenCalledTimes(1);
@@ -376,11 +388,11 @@ describe('FocusMonitor', () => {
fakeActiveElement = buttonElement;
expect(parent.classList.length)
- .toBe(3, 'Parent should have exactly 2 focus classes and the `parent` class');
+ .withContext('Parent should have exactly 2 focus classes and the `parent` class').toBe(3);
expect(parent.classList.contains('cdk-focused'))
- .toBe(true, 'Parent should have cdk-focused class');
+ .withContext('Parent should have cdk-focused class').toBe(true);
expect(parent.classList.contains('cdk-mouse-focused'))
- .toBe(true, 'Parent should have cdk-mouse-focused class');
+ .withContext('Parent should have cdk-mouse-focused class').toBe(true);
expect(changeHandler).toHaveBeenCalledTimes(2);
expect(changeHandler).toHaveBeenCalledWith('mouse');
expect(buttonElement.focus).toHaveBeenCalledTimes(1);
@@ -462,7 +474,8 @@ describe('cdkMonitorFocus', () => {
});
it('should initially not be focused', () => {
- expect(buttonElement.classList.length).toBe(0, 'button should not have focus classes');
+ expect(buttonElement.classList.length)
+ .withContext('button should not have focus classes').toBe(0);
});
it('should detect focus via keyboard', fakeAsync(() => {
@@ -473,11 +486,11 @@ describe('cdkMonitorFocus', () => {
flush();
expect(buttonElement.classList.length)
- .toBe(2, 'button should have exactly 2 focus classes');
+ .withContext('button should have exactly 2 focus classes').toBe(2);
expect(buttonElement.classList.contains('cdk-focused'))
- .toBe(true, 'button should have cdk-focused class');
+ .withContext('button should have cdk-focused class').toBe(true);
expect(buttonElement.classList.contains('cdk-keyboard-focused'))
- .toBe(true, 'button should have cdk-keyboard-focused class');
+ .withContext('button should have cdk-keyboard-focused class').toBe(true);
expect(fixture.componentInstance.focusChanged).toHaveBeenCalledWith('keyboard');
}));
@@ -489,11 +502,11 @@ describe('cdkMonitorFocus', () => {
flush();
expect(buttonElement.classList.length)
- .toBe(2, 'button should have exactly 2 focus classes');
+ .withContext('button should have exactly 2 focus classes').toBe(2);
expect(buttonElement.classList.contains('cdk-focused'))
- .toBe(true, 'button should have cdk-focused class');
+ .withContext('button should have cdk-focused class').toBe(true);
expect(buttonElement.classList.contains('cdk-mouse-focused'))
- .toBe(true, 'button should have cdk-mouse-focused class');
+ .withContext('button should have cdk-mouse-focused class').toBe(true);
expect(fixture.componentInstance.focusChanged).toHaveBeenCalledWith('mouse');
}));
@@ -505,11 +518,11 @@ describe('cdkMonitorFocus', () => {
tick(TOUCH_BUFFER_MS);
expect(buttonElement.classList.length)
- .toBe(2, 'button should have exactly 2 focus classes');
+ .withContext('button should have exactly 2 focus classes').toBe(2);
expect(buttonElement.classList.contains('cdk-focused'))
- .toBe(true, 'button should have cdk-focused class');
+ .withContext('button should have cdk-focused class').toBe(true);
expect(buttonElement.classList.contains('cdk-touch-focused'))
- .toBe(true, 'button should have cdk-touch-focused class');
+ .withContext('button should have cdk-touch-focused class').toBe(true);
expect(fixture.componentInstance.focusChanged).toHaveBeenCalledWith('touch');
}));
@@ -520,11 +533,11 @@ describe('cdkMonitorFocus', () => {
tick();
expect(buttonElement.classList.length)
- .toBe(2, 'button should have exactly 2 focus classes');
+ .withContext('button should have exactly 2 focus classes').toBe(2);
expect(buttonElement.classList.contains('cdk-focused'))
- .toBe(true, 'button should have cdk-focused class');
+ .withContext('button should have cdk-focused class').toBe(true);
expect(buttonElement.classList.contains('cdk-program-focused'))
- .toBe(true, 'button should have cdk-program-focused class');
+ .withContext('button should have cdk-program-focused class').toBe(true);
expect(fixture.componentInstance.focusChanged).toHaveBeenCalledWith('program');
}));
@@ -534,14 +547,14 @@ describe('cdkMonitorFocus', () => {
tick();
expect(buttonElement.classList.length)
- .toBe(2, 'button should have exactly 2 focus classes');
+ .withContext('button should have exactly 2 focus classes').toBe(2);
expect(fixture.componentInstance.focusChanged).toHaveBeenCalledWith('program');
buttonElement.blur();
fixture.detectChanges();
expect(buttonElement.classList.length)
- .toBe(0, 'button should not have any focus classes');
+ .withContext('button should not have any focus classes').toBe(0);
expect(fixture.componentInstance.focusChanged).toHaveBeenCalledWith(null);
}));
});
@@ -567,7 +580,8 @@ describe('cdkMonitorFocus', () => {
fixture.detectChanges();
tick();
- expect(parentElement.classList.length).toBe(2, 'button should have exactly 2 focus classes');
+ expect(parentElement.classList.length)
+ .withContext('button should have exactly 2 focus classes').toBe(2);
}));
it('should not add focus classes on child focus', fakeAsync(() => {
@@ -575,7 +589,8 @@ describe('cdkMonitorFocus', () => {
fixture.detectChanges();
tick();
- expect(parentElement.classList.length).toBe(0, 'button should not have any focus classes');
+ expect(parentElement.classList.length)
+ .withContext('button should not have any focus classes').toBe(0);
}));
});
@@ -600,7 +615,8 @@ describe('cdkMonitorFocus', () => {
fixture.detectChanges();
tick();
- expect(parentElement.classList.length).toBe(2, 'button should have exactly 2 focus classes');
+ expect(parentElement.classList.length)
+ .withContext('button should have exactly 2 focus classes').toBe(2);
}));
it('should add focus classes on child focus', fakeAsync(() => {
@@ -608,7 +624,8 @@ describe('cdkMonitorFocus', () => {
fixture.detectChanges();
tick();
- expect(parentElement.classList.length).toBe(2, 'button should have exactly 2 focus classes');
+ expect(parentElement.classList.length)
+ .withContext('button should have exactly 2 focus classes').toBe(2);
}));
});
diff --git a/src/cdk/a11y/focus-trap/event-listener-inert-strategy.spec.ts b/src/cdk/a11y/focus-trap/event-listener-inert-strategy.spec.ts
index 5ca20890ebab..e92317c6b44b 100644
--- a/src/cdk/a11y/focus-trap/event-listener-inert-strategy.spec.ts
+++ b/src/cdk/a11y/focus-trap/event-listener-inert-strategy.spec.ts
@@ -23,9 +23,9 @@ describe('EventListenerFocusTrapInertStrategy', () => {
componentInstance.outsideFocusableElement.nativeElement.focus();
flush();
- expect(componentInstance.activeElement).toBe(
- componentInstance.firstFocusableElement.nativeElement,
- 'Expected first focusable element to be focused');
+ expect(componentInstance.activeElement)
+ .withContext('Expected first focusable element to be focused')
+ .toBe(componentInstance.firstFocusableElement.nativeElement);
}));
it('does not intercept focus when focus moves to another element in the FocusTrap',
@@ -37,9 +37,9 @@ describe('EventListenerFocusTrapInertStrategy', () => {
componentInstance.secondFocusableElement.nativeElement.focus();
flush();
- expect(componentInstance.activeElement).toBe(
- componentInstance.secondFocusableElement.nativeElement,
- 'Expected second focusable element to be focused');
+ expect(componentInstance.activeElement)
+ .withContext('Expected second focusable element to be focused')
+ .toBe(componentInstance.secondFocusableElement.nativeElement);
}));
it('should not intercept focus if it moved outside the trap and back in again',
@@ -52,8 +52,9 @@ describe('EventListenerFocusTrapInertStrategy', () => {
secondFocusableElement.nativeElement.focus();
flush();
- expect(fixture.componentInstance.activeElement).toBe(secondFocusableElement.nativeElement,
- 'Expected second focusable element to be focused');
+ expect(fixture.componentInstance.activeElement)
+ .withContext('Expected second focusable element to be focused')
+ .toBe(secondFocusableElement.nativeElement);
}));
});
diff --git a/src/cdk/a11y/focus-trap/focus-trap.spec.ts b/src/cdk/a11y/focus-trap/focus-trap.spec.ts
index df4a924da17a..f6beedc5100a 100644
--- a/src/cdk/a11y/focus-trap/focus-trap.spec.ts
+++ b/src/cdk/a11y/focus-trap/focus-trap.spec.ts
@@ -49,8 +49,9 @@ describe('FocusTrap', () => {
const result = focusTrapInstance.focusFirstTabbableElement();
expect(getActiveElement().nodeName.toLowerCase())
- .toBe('input', 'Expected input element to be focused');
- expect(result).toBe(true, 'Expected return value to be true if focus was shifted.');
+ .withContext('Expected input element to be focused').toBe('input');
+ expect(result)
+ .withContext('Expected return value to be true if focus was shifted.').toBe(true);
});
it('should wrap focus from start to end', () => {
@@ -63,9 +64,10 @@ describe('FocusTrap', () => {
const lastElement = platform.IOS ? 'input' : 'button';
expect(getActiveElement().nodeName.toLowerCase())
- .toBe(lastElement, `Expected ${lastElement} element to be focused`);
+ .withContext(`Expected ${lastElement} element to be focused`).toBe(lastElement);
- expect(result).toBe(true, 'Expected return value to be true if focus was shifted.');
+ expect(result)
+ .withContext('Expected return value to be true if focus was shifted.').toBe(true);
});
it('should return false if it did not manage to find a focusable element', () => {
@@ -303,18 +305,18 @@ describe('FocusTrap', () => {
const outlet: HTMLElement = fixture.nativeElement.querySelector('.portal-outlet');
expect(outlet.querySelectorAll('button').length)
- .toBe(0, 'Expected no buttons inside the outlet on init.');
+ .withContext('Expected no buttons inside the outlet on init.').toBe(0);
expect(outlet.querySelectorAll('.cdk-focus-trap-anchor').length)
- .toBe(0, 'Expected no focus trap anchors inside the outlet on init.');
+ .withContext('Expected no focus trap anchors inside the outlet on init.').toBe(0);
const portal = new TemplatePortal(instance.template, instance.viewContainerRef);
instance.portalOutlet.attachTemplatePortal(portal);
fixture.detectChanges();
expect(outlet.querySelectorAll('button').length)
- .toBe(1, 'Expected one button inside the outlet after attaching.');
+ .withContext('Expected one button inside the outlet after attaching.').toBe(1);
expect(outlet.querySelectorAll('.cdk-focus-trap-anchor').length)
- .toBe(2, 'Expected two focus trap anchors in the outlet after attaching.');
+ .withContext('Expected two focus trap anchors in the outlet after attaching.').toBe(2);
});
});
diff --git a/src/cdk/a11y/high-contrast-mode/high-contrast-mode-detector.spec.ts b/src/cdk/a11y/high-contrast-mode/high-contrast-mode-detector.spec.ts
index fa80bfc6a0e2..4942799d040f 100644
--- a/src/cdk/a11y/high-contrast-mode/high-contrast-mode-detector.spec.ts
+++ b/src/cdk/a11y/high-contrast-mode/high-contrast-mode-detector.spec.ts
@@ -19,7 +19,8 @@ describe('HighContrastModeDetector', () => {
fakePlatform.isBrowser = false;
const detector = new HighContrastModeDetector(fakePlatform, {});
expect(detector.getHighContrastMode())
- .toBe(HighContrastMode.NONE, 'Expected high-contrast mode `NONE` on non-browser platforms');
+ .withContext('Expected high-contrast mode `NONE` on non-browser platforms')
+ .toBe(HighContrastMode.NONE);
});
it('should not apply any css classes for non-browser platforms', () => {
@@ -28,26 +29,28 @@ describe('HighContrastModeDetector', () => {
const detector = new HighContrastModeDetector(fakePlatform, fakeDocument);
detector._applyBodyHighContrastModeCssClasses();
expect(fakeDocument.body.className)
- .toBe('', 'Expected body not to have any CSS classes in non-browser platforms');
+ .withContext('Expected body not to have any CSS classes in non-browser platforms').toBe('');
});
it('should detect WHITE_ON_BLACK when backgrounds are coerced to black', () => {
const detector = new HighContrastModeDetector(fakePlatform, getFakeDocument('rgb(0,0,0)'));
expect(detector.getHighContrastMode())
- .toBe(HighContrastMode.WHITE_ON_BLACK, 'Expected high-contrast mode `WHITE_ON_BLACK`');
+ .withContext('Expected high-contrast mode `WHITE_ON_BLACK`')
+ .toBe(HighContrastMode.WHITE_ON_BLACK);
});
it('should detect BLACK_ON_WHITE when backgrounds are coerced to white ', () => {
const detector =
new HighContrastModeDetector(fakePlatform, getFakeDocument('rgb(255,255,255)'));
expect(detector.getHighContrastMode())
- .toBe(HighContrastMode.BLACK_ON_WHITE, 'Expected high-contrast mode `BLACK_ON_WHITE`');
+ .withContext('Expected high-contrast mode `BLACK_ON_WHITE`')
+ .toBe(HighContrastMode.BLACK_ON_WHITE);
});
it('should detect NONE when backgrounds are not coerced ', () => {
const detector = new HighContrastModeDetector(fakePlatform, getFakeDocument('rgb(1,2,3)'));
expect(detector.getHighContrastMode())
- .toBe(HighContrastMode.NONE, 'Expected high-contrast mode `NONE`');
+ .withContext('Expected high-contrast mode `NONE`').toBe(HighContrastMode.NONE);
});
it('should apply css classes for BLACK_ON_WHITE high-contrast mode', () => {
@@ -71,7 +74,7 @@ describe('HighContrastModeDetector', () => {
const detector = new HighContrastModeDetector(fakePlatform, fakeDocument);
detector._applyBodyHighContrastModeCssClasses();
expect(fakeDocument.body.className)
- .toBe('', 'Expected body not to have any CSS classes in non-browser platforms');
+ .withContext('Expected body not to have any CSS classes in non-browser platforms').toBe('');
});
});
diff --git a/src/cdk/a11y/interactivity-checker/interactivity-checker.spec.ts b/src/cdk/a11y/interactivity-checker/interactivity-checker.spec.ts
index b6b55e2b8904..96841f168576 100644
--- a/src/cdk/a11y/interactivity-checker/interactivity-checker.spec.ts
+++ b/src/cdk/a11y/interactivity-checker/interactivity-checker.spec.ts
@@ -28,7 +28,7 @@ describe('InteractivityChecker', () => {
elements.forEach(el => {
expect(checker.isDisabled(el))
- .toBe(true, `Expected <${el.nodeName} disabled> to be disabled`);
+ .withContext(`Expected <${el.nodeName} disabled> to be disabled`).toBe(true);
});
});
@@ -38,7 +38,7 @@ describe('InteractivityChecker', () => {
elements.forEach(el => {
expect(checker.isDisabled(el))
- .toBe(false, `Expected <${el.nodeName}> not to be disabled`);
+ .withContext(`Expected <${el.nodeName}> not to be disabled`).toBe(false);
});
});
});
@@ -50,7 +50,7 @@ describe('InteractivityChecker', () => {
const input = testContainerElement.querySelector('input') as HTMLElement;
expect(checker.isVisible(input))
- .toBe(false, 'Expected element with `display: none` to not be visible');
+ .withContext('Expected element with `display: none` to not be visible').toBe(false);
});
it('should return false for the child of a `display: none` element', () => {
@@ -61,7 +61,7 @@ describe('InteractivityChecker', () => {
const input = testContainerElement.querySelector('input') as HTMLElement;
expect(checker.isVisible(input))
- .toBe(false, 'Expected element with `display: none` parent to not be visible');
+ .withContext('Expected element with `display: none` parent to not be visible').toBe(false);
});
it('should return false for a `visibility: hidden` element', () => {
@@ -70,7 +70,7 @@ describe('InteractivityChecker', () => {
const input = testContainerElement.querySelector('input') as HTMLElement;
expect(checker.isVisible(input))
- .toBe(false, 'Expected element with `visibility: hidden` to not be visible');
+ .withContext('Expected element with `visibility: hidden` to not be visible').toBe(false);
});
it('should return false for the child of a `visibility: hidden` element', () => {
@@ -81,7 +81,8 @@ describe('InteractivityChecker', () => {
const input = testContainerElement.querySelector('input') as HTMLElement;
expect(checker.isVisible(input))
- .toBe(false, 'Expected element with `visibility: hidden` parent to not be visible');
+ .withContext('Expected element with `visibility: hidden` parent to not be visible')
+ .toBe(false);
});
it('should return true for an element with `visibility: hidden` ancestor and *closer* ' +
@@ -95,8 +96,8 @@ describe('InteractivityChecker', () => {
const input = testContainerElement.querySelector('input') as HTMLElement;
expect(checker.isVisible(input))
- .toBe(true, 'Expected element with `visibility: hidden` ancestor and closer ' +
- '`visibility: visible` ancestor to be visible');
+ .withContext('Expected element with `visibility: hidden` ancestor and closer ' +
+ '`visibility: visible` ancestor to be visible').toBe(true);
});
it('should return true for an element without visibility modifiers', () => {
@@ -104,7 +105,7 @@ describe('InteractivityChecker', () => {
testContainerElement.appendChild(input);
expect(checker.isVisible(input))
- .toBe(true, 'Expected element without visibility modifiers to be visible');
+ .withContext('Expected element without visibility modifiers to be visible').toBe(true);
});
});
@@ -114,7 +115,8 @@ describe('InteractivityChecker', () => {
appendElements(elements);
elements.forEach(el => {
- expect(checker.isFocusable(el)).toBe(true, `Expected <${el.nodeName}> to be focusable`);
+ expect(checker.isFocusable(el))
+ .withContext(`Expected <${el.nodeName}> to be focusable`).toBe(true);
});
});
@@ -123,7 +125,8 @@ describe('InteractivityChecker', () => {
anchor.href = 'google.com';
testContainerElement.appendChild(anchor);
- expect(checker.isFocusable(anchor)).toBe(true, `Expected with href to be focusable`);
+ expect(checker.isFocusable(anchor))
+ .withContext(`Expected with href to be focusable`).toBe(true);
});
it('should return false for an anchor without an href', () => {
@@ -131,7 +134,7 @@ describe('InteractivityChecker', () => {
testContainerElement.appendChild(anchor);
expect(checker.isFocusable(anchor))
- .toBe(false, `Expected without href not to be focusable`);
+ .withContext(`Expected without href not to be focusable`).toBe(false);
});
it('should return false for disabled form controls', () => {
@@ -141,7 +144,7 @@ describe('InteractivityChecker', () => {
elements.forEach(el => {
expect(checker.isFocusable(el))
- .toBe(false, `Expected <${el.nodeName} disabled> not to be focusable`);
+ .withContext(`Expected <${el.nodeName} disabled> not to be focusable`).toBe(false);
});
});
@@ -151,7 +154,7 @@ describe('InteractivityChecker', () => {
const input = testContainerElement.querySelector('input') as HTMLElement;
expect(checker.isFocusable(input))
- .toBe(false, 'Expected element with `display: none` to not be visible');
+ .withContext('Expected element with `display: none` to not be visible').toBe(false);
});
it('should return true for a `display: none` element with ignoreVisibility', () => {
@@ -162,7 +165,7 @@ describe('InteractivityChecker', () => {
config.ignoreVisibility = true;
expect(checker.isFocusable(input, config))
- .toBe(true, 'Expected element with `display: none` to be focusable');
+ .withContext('Expected element with `display: none` to be focusable').toBe(true);
});
it('should return false for the child of a `display: none` element', () => {
@@ -173,7 +176,7 @@ describe('InteractivityChecker', () => {
const input = testContainerElement.querySelector('input') as HTMLElement;
expect(checker.isFocusable(input))
- .toBe(false, 'Expected element with `display: none` parent to not be visible');
+ .withContext('Expected element with `display: none` parent to not be visible').toBe(false);
});
it('should return false for a `visibility: hidden` element', () => {
@@ -182,7 +185,7 @@ describe('InteractivityChecker', () => {
const input = testContainerElement.querySelector('input') as HTMLElement;
expect(checker.isFocusable(input))
- .toBe(false, 'Expected element with `visibility: hidden` not to be focusable');
+ .withContext('Expected element with `visibility: hidden` not to be focusable').toBe(false);
});
it('should return false for the child of a `visibility: hidden` element', () => {
@@ -193,7 +196,8 @@ describe('InteractivityChecker', () => {
const input = testContainerElement.querySelector('input') as HTMLElement;
expect(checker.isFocusable(input))
- .toBe(false, 'Expected element with `visibility: hidden` parent not to be focusable');
+ .withContext('Expected element with `visibility: hidden` parent not to be focusable')
+ .toBe(false);
});
it('should return true for an element with `visibility: hidden` ancestor and *closer* ' +
@@ -207,8 +211,8 @@ describe('InteractivityChecker', () => {
const input = testContainerElement.querySelector('input') as HTMLElement;
expect(checker.isFocusable(input))
- .toBe(true, 'Expected element with `visibility: hidden` ancestor and closer ' +
- '`visibility: visible` ancestor to be focusable');
+ .withContext('Expected element with `visibility: hidden` ancestor and closer ' +
+ '`visibility: visible` ancestor to be focusable').toBe(true);
});
it('should return false for an element with an empty tabindex', () => {
@@ -217,7 +221,7 @@ describe('InteractivityChecker', () => {
testContainerElement.appendChild(element);
expect(checker.isFocusable(element))
- .toBe(false, `Expected element with tabindex="" not to be focusable`);
+ .withContext(`Expected element with tabindex="" not to be focusable`).toBe(false);
});
it('should return false for an element with a non-numeric tabindex', () => {
@@ -226,7 +230,7 @@ describe('InteractivityChecker', () => {
testContainerElement.appendChild(element);
expect(checker.isFocusable(element))
- .toBe(false, `Expected element with non-numeric tabindex not to be focusable`);
+ .withContext(`Expected element with non-numeric tabindex not to be focusable`).toBe(false);
});
it('should return true for an element with contenteditable', () => {
@@ -235,7 +239,7 @@ describe('InteractivityChecker', () => {
testContainerElement.appendChild(element);
expect(checker.isFocusable(element))
- .toBe(true, `Expected element with contenteditable to be focusable`);
+ .withContext(`Expected element with contenteditable to be focusable`).toBe(true);
});
@@ -245,7 +249,7 @@ describe('InteractivityChecker', () => {
elements.forEach(el => {
expect(checker.isFocusable(el))
- .toBe(false, `Expected <${el.nodeName}> not to be focusable`);
+ .withContext(`Expected <${el.nodeName}> not to be focusable`).toBe(false);
});
});
@@ -307,7 +311,8 @@ describe('InteractivityChecker', () => {
appendElements(elements);
elements.forEach(el => {
- expect(checker.isTabbable(el)).toBe(true, `Expected <${el.nodeName}> to be tabbable`);
+ expect(checker.isTabbable(el))
+ .withContext(`Expected <${el.nodeName}> to be tabbable`).toBe(true);
});
});
@@ -323,7 +328,7 @@ describe('InteractivityChecker', () => {
elements.forEach(el => {
expect(checker.isFocusable(el))
- .toBe(true, `Expected <${el.nodeName} tabindex="0"> to be focusable`);
+ .withContext(`Expected <${el.nodeName} tabindex="0"> to be focusable`).toBe(true);
});
});
@@ -339,7 +344,7 @@ describe('InteractivityChecker', () => {
elements.forEach(el => {
expect(checker.isTabbable(el))
- .toBe(false, `Expected <${el.nodeName} tabindex="-1"> not to be tabbable`);
+ .withContext(`Expected <${el.nodeName} tabindex="-1"> not to be tabbable`).toBe(false);
});
});
@@ -355,7 +360,7 @@ describe('InteractivityChecker', () => {
elements.forEach(el => {
expect(checker.isTabbable(el))
- .toBe(true, `Expected <${el.nodeName} tabindex="0"> to be tabbable`);
+ .withContext(`Expected <${el.nodeName} tabindex="0"> to be tabbable`).toBe(true);
});
});
diff --git a/src/cdk/a11y/key-manager/list-key-manager.spec.ts b/src/cdk/a11y/key-manager/list-key-manager.spec.ts
index d6ebda9b405e..194dc9f67e59 100644
--- a/src/cdk/a11y/key-manager/list-key-manager.spec.ts
+++ b/src/cdk/a11y/key-manager/list-key-manager.spec.ts
@@ -153,11 +153,13 @@ describe('Key managers', () => {
it('should activate the first item when pressing down on a clean key manager', () => {
keyManager = new ListKeyManager(itemList);
- expect(keyManager.activeItemIndex).toBe(-1, 'Expected active index to default to -1.');
+ expect(keyManager.activeItemIndex)
+ .withContext('Expected active index to default to -1.').toBe(-1);
keyManager.onKeydown(fakeKeyEvents.downArrow);
- expect(keyManager.activeItemIndex).toBe(0, 'Expected first item to become active.');
+ expect(keyManager.activeItemIndex)
+ .withContext('Expected first item to become active.').toBe(0);
});
it('should not prevent the default keyboard action when pressing tab', () => {
@@ -266,14 +268,14 @@ describe('Key managers', () => {
keyManager.onKeydown(this.nextKeyEvent);
expect(keyManager.activeItemIndex)
- .toBe(1, 'Expected active item to be 1 after one next key event.');
+ .withContext('Expected active item to be 1 after one next key event.').toBe(1);
expect(keyManager.setActiveItem).not.toHaveBeenCalledWith(0);
expect(keyManager.setActiveItem).toHaveBeenCalledWith(1);
expect(keyManager.setActiveItem).not.toHaveBeenCalledWith(2);
keyManager.onKeydown(this.nextKeyEvent);
expect(keyManager.activeItemIndex)
- .toBe(2, 'Expected active item to be 2 after two next key events.');
+ .withContext('Expected active item to be 2 after two next key events.').toBe(2);
expect(keyManager.setActiveItem).toHaveBeenCalledWith(2);
expect(keyManager.setActiveItem).not.toHaveBeenCalledWith(0);
});
@@ -283,7 +285,8 @@ describe('Key managers', () => {
keyManager.onKeydown(this.nextKeyEvent);
expect(keyManager.activeItemIndex)
- .toBe(0, 'Expected active item to be 0 after next key if active item was null.');
+ .withContext('Expected active item to be 0 after next key if active item was null.')
+ .toBe(0);
expect(keyManager.setActiveItem).toHaveBeenCalledWith(0);
expect(keyManager.setActiveItem).not.toHaveBeenCalledWith(1);
expect(keyManager.setActiveItem).not.toHaveBeenCalledWith(2);
@@ -293,13 +296,14 @@ describe('Key managers', () => {
keyManager.onKeydown(this.nextKeyEvent);
expect(keyManager.activeItemIndex)
- .toBe(1, 'Expected active item to be 1 after one next key event.');
+ .withContext('Expected active item to be 1 after one next key event.').toBe(1);
expect(keyManager.setActiveItem).not.toHaveBeenCalledWith(0);
expect(keyManager.setActiveItem).toHaveBeenCalledWith(1);
keyManager.onKeydown(this.prevKeyEvent);
expect(keyManager.activeItemIndex)
- .toBe(0, 'Expected active item to be 0 after one next and one previous key event.');
+ .withContext('Expected active item to be 0 after one next and one previous key event.')
+ .toBe(0);
expect(keyManager.setActiveItem).toHaveBeenCalledWith(0);
});
@@ -308,7 +312,8 @@ describe('Key managers', () => {
keyManager.onKeydown(this.prevKeyEvent);
expect(keyManager.activeItemIndex)
- .toBe(-1, 'Expected nothing to happen if prev event occurs and no active item.');
+ .withContext('Expected nothing to happen if prev event occurs and no active item.')
+ .toBe(-1);
expect(keyManager.setActiveItem).not.toHaveBeenCalledWith(0);
expect(keyManager.setActiveItem).not.toHaveBeenCalledWith(1);
expect(keyManager.setActiveItem).not.toHaveBeenCalledWith(2);
@@ -322,7 +327,7 @@ describe('Key managers', () => {
// Next event should skip past disabled item from 0 to 2
keyManager.onKeydown(this.nextKeyEvent);
expect(keyManager.activeItemIndex)
- .toBe(2, 'Expected active item to skip past disabled item on next event.');
+ .withContext('Expected active item to skip past disabled item on next event.').toBe(2);
expect(keyManager.setActiveItem).not.toHaveBeenCalledWith(0);
expect(keyManager.setActiveItem).not.toHaveBeenCalledWith(1);
expect(keyManager.setActiveItem).toHaveBeenCalledWith(2);
@@ -330,7 +335,7 @@ describe('Key managers', () => {
// Previous event should skip past disabled item from 2 to 0
keyManager.onKeydown(this.prevKeyEvent);
expect(keyManager.activeItemIndex)
- .toBe(0, 'Expected active item to skip past disabled item on up arrow.');
+ .withContext('Expected active item to skip past disabled item on up arrow.').toBe(0);
expect(keyManager.setActiveItem).toHaveBeenCalledWith(0);
expect(keyManager.setActiveItem).not.toHaveBeenCalledWith(1);
});
@@ -344,14 +349,16 @@ describe('Key managers', () => {
keyManager.onKeydown(this.nextKeyEvent);
expect(keyManager.activeItemIndex)
- .toBe(1, 'Expected active item to be 1 after one next event when disabled not set.');
+ .withContext('Expected active item to be 1 after one next event when disabled not set.')
+ .toBe(1);
expect(keyManager.setActiveItem).not.toHaveBeenCalledWith(0);
expect(keyManager.setActiveItem).toHaveBeenCalledWith(1);
expect(keyManager.setActiveItem).not.toHaveBeenCalledWith(2);
keyManager.onKeydown(this.nextKeyEvent);
expect(keyManager.activeItemIndex)
- .toBe(2, 'Expected active item to be 2 after two next events when disabled not set.');
+ .withContext('Expected active item to be 2 after two next events when ' +
+ 'disabled not set.').toBe(2);
expect(keyManager.setActiveItem).not.toHaveBeenCalledWith(0);
expect(keyManager.setActiveItem).toHaveBeenCalledWith(2);
});
@@ -360,22 +367,22 @@ describe('Key managers', () => {
keyManager.onKeydown(this.nextKeyEvent);
keyManager.onKeydown(this.nextKeyEvent);
expect(keyManager.activeItemIndex)
- .toBe(2, `Expected last item of the list to be active.`);
+ .withContext(`Expected last item of the list to be active.`).toBe(2);
// This next event would move active item past the end of the list
keyManager.onKeydown(this.nextKeyEvent);
expect(keyManager.activeItemIndex)
- .toBe(2, `Expected active item to remain at the end of the list.`);
+ .withContext(`Expected active item to remain at the end of the list.`).toBe(2);
keyManager.onKeydown(this.prevKeyEvent);
keyManager.onKeydown(this.prevKeyEvent);
expect(keyManager.activeItemIndex)
- .toBe(0, `Expected first item of the list to be active.`);
+ .withContext(`Expected first item of the list to be active.`).toBe(0);
// This prev event would move active item past the beginning of the list
keyManager.onKeydown(this.prevKeyEvent);
expect(keyManager.activeItemIndex)
- .toBe(0, `Expected active item to remain at the beginning of the list.`);
+ .withContext(`Expected active item to remain at the beginning of the list.`).toBe(0);
});
it('should not move active item to end when the last item is disabled', () => {
@@ -385,12 +392,12 @@ describe('Key managers', () => {
keyManager.onKeydown(this.nextKeyEvent);
expect(keyManager.activeItemIndex)
- .toBe(1, `Expected second item of the list to be active.`);
+ .withContext(`Expected second item of the list to be active.`).toBe(1);
// This next key event would set active item to the last item, which is disabled
keyManager.onKeydown(this.nextKeyEvent);
expect(keyManager.activeItemIndex)
- .toBe(1, `Expected the second item to remain active.`);
+ .withContext(`Expected the second item to remain active.`).toBe(1);
expect(keyManager.setActiveItem).not.toHaveBeenCalledWith(2);
});
@@ -456,20 +463,21 @@ describe('Key managers', () => {
it('should setActiveItem()', () => {
expect(keyManager.activeItemIndex)
- .toBe(0, `Expected first item of the list to be active.`);
+ .withContext(`Expected first item of the list to be active.`).toBe(0);
keyManager.setActiveItem(1);
expect(keyManager.activeItemIndex)
- .toBe(1, `Expected activeItemIndex to be updated when setActiveItem() was called.`);
+ .withContext(`Expected activeItemIndex to be updated when setActiveItem() was called.`)
+ .toBe(1);
});
it('should be able to set the active item by reference', () => {
expect(keyManager.activeItemIndex)
- .toBe(0, `Expected first item of the list to be active.`);
+ .withContext(`Expected first item of the list to be active.`).toBe(0);
keyManager.setActiveItem(itemList.toArray()[2]);
expect(keyManager.activeItemIndex)
- .toBe(2, `Expected activeItemIndex to be updated.`);
+ .withContext(`Expected activeItemIndex to be updated.`).toBe(2);
});
it('should be able to set the active item without emitting an event', () => {
@@ -489,26 +497,31 @@ describe('Key managers', () => {
it('should expose the active item correctly', () => {
keyManager.onKeydown(fakeKeyEvents.downArrow);
- expect(keyManager.activeItemIndex).toBe(1, 'Expected active item to be the second option.');
+ expect(keyManager.activeItemIndex)
+ .withContext('Expected active item to be the second option.').toBe(1);
expect(keyManager.activeItem)
- .toBe(itemList.toArray()[1], 'Expected the active item to match the second option.');
+ .withContext('Expected the active item to match the second option.')
+ .toBe(itemList.toArray()[1]);
keyManager.onKeydown(fakeKeyEvents.downArrow);
- expect(keyManager.activeItemIndex).toBe(2, 'Expected active item to be the third option.');
+ expect(keyManager.activeItemIndex)
+ .withContext('Expected active item to be the third option.').toBe(2);
expect(keyManager.activeItem)
- .toBe(itemList.toArray()[2], 'Expected the active item ID to match the third option.');
+ .withContext('Expected the active item ID to match the third option.')
+ .toBe(itemList.toArray()[2]);
});
it('should setFirstItemActive()', () => {
keyManager.onKeydown(fakeKeyEvents.downArrow);
keyManager.onKeydown(fakeKeyEvents.downArrow);
expect(keyManager.activeItemIndex)
- .toBe(2, `Expected last item of the list to be active.`);
+ .withContext(`Expected last item of the list to be active.`).toBe(2);
keyManager.setFirstItemActive();
expect(keyManager.activeItemIndex)
- .toBe(0, `Expected setFirstItemActive() to set the active item to the first item.`);
+ .withContext(`Expected setFirstItemActive() to set the active item to the first item.`)
+ .toBe(0);
});
it('should set the active item to the second item if the first one is disabled', () => {
@@ -518,16 +531,17 @@ describe('Key managers', () => {
keyManager.setFirstItemActive();
expect(keyManager.activeItemIndex)
- .toBe(1, `Expected the second item to be active if the first was disabled.`);
+ .withContext(`Expected the second item to be active if the first was disabled.`).toBe(1);
});
it('should setLastItemActive()', () => {
expect(keyManager.activeItemIndex)
- .toBe(0, `Expected first item of the list to be active.`);
+ .withContext(`Expected first item of the list to be active.`).toBe(0);
keyManager.setLastItemActive();
expect(keyManager.activeItemIndex)
- .toBe(2, `Expected setLastItemActive() to set the active item to the last item.`);
+ .withContext(`Expected setLastItemActive() to set the active item to the last item.`)
+ .toBe(2);
});
it('should set the active item to the second to last item if the last is disabled', () => {
@@ -537,16 +551,18 @@ describe('Key managers', () => {
keyManager.setLastItemActive();
expect(keyManager.activeItemIndex)
- .toBe(1, `Expected the second to last item to be active if the last was disabled.`);
+ .withContext(`Expected the second to last item to be active if the last was disabled.`)
+ .toBe(1);
});
it('should setNextItemActive()', () => {
expect(keyManager.activeItemIndex)
- .toBe(0, `Expected first item of the list to be active.`);
+ .withContext(`Expected first item of the list to be active.`).toBe(0);
keyManager.setNextItemActive();
expect(keyManager.activeItemIndex)
- .toBe(1, `Expected setNextItemActive() to set the active item to the next item.`);
+ .withContext(`Expected setNextItemActive() to set the active item to the next item.`)
+ .toBe(1);
});
it('should set the active item to the next enabled item if next is disabled', () => {
@@ -555,21 +571,22 @@ describe('Key managers', () => {
itemList.reset(items);
expect(keyManager.activeItemIndex)
- .toBe(0, `Expected first item of the list to be active.`);
+ .withContext(`Expected first item of the list to be active.`).toBe(0);
keyManager.setNextItemActive();
expect(keyManager.activeItemIndex)
- .toBe(2, `Expected setNextItemActive() to only set enabled items as active.`);
+ .withContext(`Expected setNextItemActive() to only set enabled items as active.`).toBe(2);
});
it('should setPreviousItemActive()', () => {
keyManager.onKeydown(fakeKeyEvents.downArrow);
expect(keyManager.activeItemIndex)
- .toBe(1, `Expected second item of the list to be active.`);
+ .withContext(`Expected second item of the list to be active.`).toBe(1);
keyManager.setPreviousItemActive();
expect(keyManager.activeItemIndex)
- .toBe(0, `Expected setPreviousItemActive() to set the active item to the previous.`);
+ .withContext(`Expected setPreviousItemActive() to set the active item to the previous.`)
+ .toBe(0);
});
it('should skip disabled items when setPreviousItemActive() is called', () => {
@@ -580,11 +597,11 @@ describe('Key managers', () => {
keyManager.onKeydown(fakeKeyEvents.downArrow);
keyManager.onKeydown(fakeKeyEvents.downArrow);
expect(keyManager.activeItemIndex)
- .toBe(2, `Expected third item of the list to be active.`);
+ .withContext(`Expected third item of the list to be active.`).toBe(2);
keyManager.setPreviousItemActive();
expect(keyManager.activeItemIndex)
- .toBe(0, `Expected setPreviousItemActive() to skip the disabled item.`);
+ .withContext(`Expected setPreviousItemActive() to skip the disabled item.`).toBe(0);
});
it('should not emit an event if the item did not change', () => {
@@ -605,7 +622,8 @@ describe('Key managers', () => {
it('should return itself to allow chaining', () => {
expect(keyManager.withWrap())
- .toEqual(keyManager, `Expected withWrap() to return an instance of ListKeyManager.`);
+ .withContext(`Expected withWrap() to return an instance of ListKeyManager.`)
+ .toEqual(keyManager);
});
it('should wrap focus when arrow keying past items while in wrap mode', () => {
@@ -613,15 +631,18 @@ describe('Key managers', () => {
keyManager.onKeydown(fakeKeyEvents.downArrow);
keyManager.onKeydown(fakeKeyEvents.downArrow);
- expect(keyManager.activeItemIndex).toBe(2, 'Expected last item to be active.');
+ expect(keyManager.activeItemIndex)
+ .withContext('Expected last item to be active.').toBe(2);
// this down arrow moves down past the end of the list
keyManager.onKeydown(fakeKeyEvents.downArrow);
- expect(keyManager.activeItemIndex).toBe(0, 'Expected active item to wrap to beginning.');
+ expect(keyManager.activeItemIndex)
+ .withContext('Expected active item to wrap to beginning.').toBe(0);
// this up arrow moves up past the beginning of the list
keyManager.onKeydown(fakeKeyEvents.upArrow);
- expect(keyManager.activeItemIndex).toBe(2, 'Expected active item to wrap to end.');
+ expect(keyManager.activeItemIndex)
+ .withContext('Expected active item to wrap to end.').toBe(2);
});
it('should set last item active when up arrow is pressed if no active item', () => {
@@ -630,13 +651,13 @@ describe('Key managers', () => {
keyManager.onKeydown(fakeKeyEvents.upArrow);
expect(keyManager.activeItemIndex)
- .toBe(2, 'Expected last item to be active on up arrow if no active item.');
+ .withContext('Expected last item to be active on up arrow if no active item.').toBe(2);
expect(keyManager.setActiveItem).not.toHaveBeenCalledWith(0);
expect(keyManager.setActiveItem).toHaveBeenCalledWith(2);
keyManager.onKeydown(fakeKeyEvents.downArrow);
expect(keyManager.activeItemIndex)
- .toBe(0, 'Expected active item to be 0 after wrapping back to beginning.');
+ .withContext('Expected active item to be 0 after wrapping back to beginning.').toBe(0);
expect(keyManager.setActiveItem).toHaveBeenCalledWith(0);
});
@@ -937,11 +958,12 @@ describe('Key managers', () => {
it('should allow setting the focused item without calling focus', () => {
expect(keyManager.activeItemIndex)
- .toBe(0, `Expected first item of the list to be active.`);
+ .withContext(`Expected first item of the list to be active.`).toBe(0);
keyManager.updateActiveItem(1);
expect(keyManager.activeItemIndex)
- .toBe(1, `Expected activeItemIndex to update after calling updateActiveItem().`);
+ .withContext(`Expected activeItemIndex to update after calling updateActiveItem().`)
+ .toBe(1);
expect(itemList.toArray()[1].focus).not.toHaveBeenCalledTimes(1);
});
diff --git a/src/cdk/a11y/live-announcer/live-announcer.spec.ts b/src/cdk/a11y/live-announcer/live-announcer.spec.ts
index 86b886cdd11f..750ebf4eb73a 100644
--- a/src/cdk/a11y/live-announcer/live-announcer.spec.ts
+++ b/src/cdk/a11y/live-announcer/live-announcer.spec.ts
@@ -102,7 +102,8 @@ describe('LiveAnnouncer', () => {
announcer.ngOnDestroy();
expect(document.body.querySelector('.cdk-live-announcer-element'))
- .toBeFalsy('Expected that the aria-live element was remove from the DOM.');
+ .withContext('Expected that the aria-live element was remove from the DOM.')
+ .toBeFalsy();
}));
it('should return a promise that resolves after the text has been announced', fakeAsync(() => {
@@ -137,7 +138,8 @@ describe('LiveAnnouncer', () => {
tick(100);
expect(document.body.querySelectorAll('.cdk-live-announcer-element').length)
- .toBe(1, 'Expected only one live announcer element in the DOM.');
+ .withContext('Expected only one live announcer element in the DOM.')
+ .toBe(1);
if (extraElement.parentNode) {
extraElement.parentNode.removeChild(extraElement);
diff --git a/src/cdk/drag-drop/directives/drag.spec.ts b/src/cdk/drag-drop/directives/drag.spec.ts
index 35f0f9183011..9624ec94d7a8 100644
--- a/src/cdk/drag-drop/directives/drag.spec.ts
+++ b/src/cdk/drag-drop/directives/drag.spec.ts
@@ -330,9 +330,9 @@ describe('CdkDrag', () => {
fixture.detectChanges();
expect(dispatchTouchEvent(document, 'touchmove').defaultPrevented)
- .toBe(true, 'Expected initial touchmove to be prevented.');
+ .withContext('Expected initial touchmove to be prevented.').toBe(true);
expect(dispatchTouchEvent(document, 'touchmove').defaultPrevented)
- .toBe(true, 'Expected subsequent touchmose to be prevented.');
+ .withContext('Expected subsequent touchmose to be prevented.').toBe(true);
dispatchTouchEvent(document, 'touchend');
fixture.detectChanges();
@@ -1057,7 +1057,9 @@ describe('CdkDrag', () => {
fixture.detectChanges();
const dragElement = fixture.componentInstance.dragElement.nativeElement;
- expect(dragElement.style.transform).toBeFalsy('Expected element not to be moved by default.');
+ expect(dragElement.style.transform)
+ .withContext('Expected element not to be moved by default.')
+ .toBeFalsy();
startDraggingViaMouse(fixture, dragElement);
currentTime += 750;
@@ -1066,7 +1068,8 @@ describe('CdkDrag', () => {
fixture.detectChanges();
expect(dragElement.style.transform)
- .toBeFalsy('Expected element not to be moved if the mouse moved before the delay.');
+ .withContext('Expected element not to be moved if the mouse moved before the delay.')
+ .toBeFalsy();
}));
it('should enable native drag interactions if mouse moves before the delay', fakeAsync(() => {
@@ -1080,7 +1083,9 @@ describe('CdkDrag', () => {
const dragElement = fixture.componentInstance.dragElement.nativeElement;
const styles = dragElement.style;
- expect(dragElement.style.transform).toBeFalsy('Expected element not to be moved by default.');
+ expect(dragElement.style.transform)
+ .withContext('Expected element not to be moved by default.')
+ .toBeFalsy();
startDraggingViaMouse(fixture, dragElement);
currentTime += 750;
@@ -1101,7 +1106,9 @@ describe('CdkDrag', () => {
fixture.detectChanges();
const dragElement = fixture.componentInstance.dragElement.nativeElement;
- expect(dragElement.style.transform).toBeFalsy('Expected element not to be moved by default.');
+ expect(dragElement.style.transform)
+ .withContext('Expected element not to be moved by default.')
+ .toBeFalsy();
dispatchMouseEvent(dragElement, 'mousedown');
fixture.detectChanges();
@@ -1112,8 +1119,9 @@ describe('CdkDrag', () => {
dispatchMouseEvent(document, 'mousemove', 50, 100);
fixture.detectChanges();
- expect(dragElement.style.transform).toBe('translate3d(50px, 100px, 0px)',
- 'Expected element to be dragged after all the time has passed.');
+ expect(dragElement.style.transform)
+ .withContext('Expected element to be dragged after all the time has passed.')
+ .toBe('translate3d(50px, 100px, 0px)');
}));
it('should not prevent the default touch action before the delay has elapsed', fakeAsync(() => {
@@ -1125,7 +1133,9 @@ describe('CdkDrag', () => {
fixture.detectChanges();
const dragElement = fixture.componentInstance.dragElement.nativeElement;
- expect(dragElement.style.transform).toBeFalsy('Expected element not to be moved by default.');
+ expect(dragElement.style.transform)
+ .withContext('Expected element not to be moved by default.')
+ .toBeFalsy();
dispatchTouchEvent(dragElement, 'touchstart');
fixture.detectChanges();
@@ -1144,7 +1154,9 @@ describe('CdkDrag', () => {
fixture.detectChanges();
const dragElement = fixture.componentInstance.dragElement.nativeElement;
- expect(dragElement.style.transform).toBeFalsy('Expected element not to be moved by default.');
+ expect(dragElement.style.transform)
+ .withContext('Expected element not to be moved by default.')
+ .toBeFalsy();
dispatchMouseEvent(dragElement, 'mousedown');
fixture.detectChanges();
@@ -1155,8 +1167,9 @@ describe('CdkDrag', () => {
dispatchMouseEvent(document, 'mousemove', 50, 100);
fixture.detectChanges();
- expect(dragElement.style.transform).toBe('translate3d(50px, 100px, 0px)',
- 'Expected element to be dragged after all the time has passed.');
+ expect(dragElement.style.transform)
+ .withContext('Expected element to be dragged after all the time has passed.')
+ .toBe('translate3d(50px, 100px, 0px)');
}));
it('should be able to configure the drag start delay based on the event type', fakeAsync(() => {
@@ -1169,15 +1182,19 @@ describe('CdkDrag', () => {
fixture.detectChanges();
const dragElement = fixture.componentInstance.dragElement.nativeElement;
- expect(dragElement.style.transform).toBeFalsy('Expected element not to be moved by default.');
+ expect(dragElement.style.transform)
+ .withContext('Expected element not to be moved by default.')
+ .toBeFalsy();
dragElementViaTouch(fixture, dragElement, 50, 100);
expect(dragElement.style.transform)
- .toBeFalsy('Expected element not to be moved via touch because it has a delay.');
+ .withContext('Expected element not to be moved via touch because it has a delay.')
+ .toBeFalsy();
dragElementViaMouse(fixture, dragElement, 50, 100);
- expect(dragElement.style.transform).toBe('translate3d(50px, 100px, 0px)',
- 'Expected element to be moved via mouse because it has no delay.');
+ expect(dragElement.style.transform)
+ .withContext('Expected element to be moved via mouse because it has no delay.')
+ .toBe('translate3d(50px, 100px, 0px)');
}));
it('should be able to get the current position', fakeAsync(() => {
@@ -1480,11 +1497,13 @@ describe('CdkDrag', () => {
dragElementViaMouse(fixture, dragElement, 50, 100);
expect(dragElement.style.transform)
- .toBeFalsy('Expected not to be able to drag the element by itself.');
+ .withContext('Expected not to be able to drag the element by itself.')
+ .toBeFalsy();
dragElementViaMouse(fixture, handle, 50, 100);
expect(dragElement.style.transform)
- .toBe('translate3d(50px, 100px, 0px)', 'Expected to drag the element by its handle.');
+ .withContext('Expected to drag the element by its handle.')
+ .toBe('translate3d(50px, 100px, 0px)');
}));
it('should disable the tap highlight while dragging via the handle', fakeAsync(() => {
@@ -2173,38 +2192,54 @@ describe('CdkDrag', () => {
const previewRect = preview.getBoundingClientRect();
const zeroPxRegex = /^0(px)?$/;
- expect(item.parentNode).toBe(document.body, 'Expected element to be moved out into the body');
- expect(item.style.position).toBe('fixed', 'Expected element to be removed from layout');
+ expect(item.parentNode)
+ .withContext('Expected element to be moved out into the body').toBe(document.body);
+ expect(item.style.position)
+ .withContext('Expected element to be removed from layout').toBe('fixed');
expect(item.style.getPropertyPriority('position'))
- .toBe('important', 'Expect element position to be !important');
+ .withContext('Expect element position to be !important').toBe('important');
// Use a regex here since some browsers normalize 0 to 0px, but others don't.
- expect(item.style.top).toMatch(zeroPxRegex, 'Expected element to be removed from layout');
- expect(item.style.left).toBe('-999em', 'Expected element to be removed from layout');
- expect(item.style.opacity).toBe('0', 'Expected element to be invisible');
- expect(preview).toBeTruthy('Expected preview to be in the DOM');
+ // Use a regex here since some browsers normalize 0 to 0px, but others don't.
+expect(item.style.top)
+ .withContext('Expected element to be removed from layout').toMatch(zeroPxRegex);
+ expect(item.style.left)
+ .withContext('Expected element to be removed from layout').toBe('-999em');
+ expect(item.style.opacity)
+ .withContext('Expected element to be invisible').toBe('0');
+ expect(preview).withContext('Expected preview to be in the DOM').toBeTruthy();
expect(preview.textContent!.trim())
- .toContain('One', 'Expected preview content to match element');
+ .withContext('Expected preview content to match element').toContain('One');
expect(preview.getAttribute('dir'))
- .toBe('ltr', 'Expected preview element to inherit the directionality.');
- expect(previewRect.width).toBe(itemRect.width, 'Expected preview width to match element');
- expect(previewRect.height).toBe(itemRect.height, 'Expected preview height to match element');
+ .withContext('Expected preview element to inherit the directionality.').toBe('ltr');
+ expect(previewRect.width)
+ .withContext('Expected preview width to match element').toBe(itemRect.width);
+ expect(previewRect.height)
+ .withContext('Expected preview height to match element').toBe(itemRect.height);
expect(preview.style.pointerEvents)
- .toBe('none', 'Expected pointer events to be disabled on the preview');
- expect(preview.style.zIndex).toBe('1000', 'Expected preview to have a high default zIndex.');
+ .withContext('Expected pointer events to be disabled on the preview').toBe('none');
+ expect(preview.style.zIndex)
+ .withContext('Expected preview to have a high default zIndex.').toBe('1000');
+ // Use a regex here since some browsers normalize 0 to 0px, but others don't.
// Use a regex here since some browsers normalize 0 to 0px, but others don't.
- expect(preview.style.margin).toMatch(zeroPxRegex, 'Expected the preview margin to be reset.');
+ expect(preview.style.margin)
+ .withContext('Expected the preview margin to be reset.').toMatch(zeroPxRegex);
dispatchMouseEvent(document, 'mouseup');
fixture.detectChanges();
flush();
expect(item.parentNode)
- .toBe(initialParent, 'Expected element to be moved back into its old parent');
- expect(item.style.position).toBeFalsy('Expected element to be within the layout');
- expect(item.style.top).toBeFalsy('Expected element to be within the layout');
- expect(item.style.left).toBeFalsy('Expected element to be within the layout');
- expect(item.style.opacity).toBeFalsy('Expected element to be visible');
- expect(preview.parentNode).toBeFalsy('Expected preview to be removed from the DOM');
+ .withContext('Expected element to be moved back into its old parent').toBe(initialParent);
+ expect(item.style.position)
+ .withContext('Expected element to be within the layout').toBeFalsy();
+ expect(item.style.top)
+ .withContext('Expected element to be within the layout').toBeFalsy();
+ expect(item.style.left)
+ .withContext('Expected element to be within the layout').toBeFalsy();
+ expect(item.style.opacity)
+ .withContext('Expected element to be visible').toBeFalsy();
+ expect(preview.parentNode)
+ .withContext('Expected preview to be removed from the DOM').toBeFalsy();
}));
it('should be able to configure the preview z-index', fakeAsync(() => {
@@ -2429,17 +2464,20 @@ describe('CdkDrag', () => {
const sourceCanvas = item.querySelector('canvas') as HTMLCanvasElement;
// via https://stackoverflow.com/a/17386803/2204158
- expect(sourceCanvas.getContext('2d')!
- .getImageData(0, 0, sourceCanvas.width, sourceCanvas.height)
- .data.some(channel => channel !== 0)).toBe(true, 'Expected source canvas to have data.');
+ // via https://stackoverflow.com/a/17386803/2204158
+expect(sourceCanvas.getContext('2d')!
+ .getImageData(0, 0, sourceCanvas.width, sourceCanvas.height)
+ .data.some(channel => channel !== 0))
+ .withContext('Expected source canvas to have data.').toBe(true);
startDraggingViaMouse(fixture, item);
const preview = document.querySelector('.cdk-drag-preview')! as HTMLElement;
const previewCanvas = preview.querySelector('canvas')!;
- expect(previewCanvas.toDataURL()).toBe(sourceCanvas.toDataURL(),
- 'Expected cloned canvas to have the same content as the source.');
+ expect(previewCanvas.toDataURL())
+ .withContext('Expected cloned canvas to have the same content as the source.')
+ .toBe(sourceCanvas.toDataURL());
}));
it('should not throw when cloning an invalid canvas', fakeAsync(() => {
@@ -2508,7 +2546,8 @@ describe('CdkDrag', () => {
tick(0);
expect(sourceRadioInput.checked)
- .toBeTruthy('Expected original radio input has preserved its original checked state');
+ .withContext('Expected original radio input has preserved its original checked state')
+ .toBeTruthy();
}));
it('should clear the ids from descendants of the preview', fakeAsync(() => {
@@ -2548,7 +2587,7 @@ describe('CdkDrag', () => {
startDraggingViaMouse(fixture, item);
expect(document.querySelector('.cdk-drag-preview')!.getAttribute('dir'))
- .toBe('rtl', 'Expected preview element to inherit the directionality.');
+ .withContext('Expected preview element to inherit the directionality.').toBe('rtl');
}));
it('should remove the preview if its `transitionend` event timed out', fakeAsync(() => {
@@ -2572,12 +2611,14 @@ describe('CdkDrag', () => {
tick(250);
expect(preview.parentNode)
- .toBeTruthy('Expected preview to be in the DOM mid-way through the transition');
+ .withContext('Expected preview to be in the DOM mid-way through the transition')
+ .toBeTruthy();
tick(500);
expect(preview.parentNode)
- .toBeFalsy('Expected preview to be removed from the DOM if the transition timed out');
+ .withContext('Expected preview to be removed from the DOM if the transition timed out')
+ .toBeFalsy();
}));
it('should be able to set a single class on a preview', fakeAsync(() => {
@@ -2689,7 +2730,8 @@ describe('CdkDrag', () => {
tick(0);
expect(preview.parentNode)
- .toBeFalsy('Expected preview to be removed from the DOM immediately');
+ .withContext('Expected preview to be removed from the DOM immediately')
+ .toBeFalsy();
}));
it('should pick out the `transform` duration if multiple properties are being transitioned',
@@ -2711,12 +2753,14 @@ describe('CdkDrag', () => {
tick(500);
expect(preview.parentNode)
- .toBeTruthy('Expected preview to be in the DOM at the end of the opacity transition');
+ .withContext('Expected preview to be in the DOM at the end of the opacity transition')
+ .toBeTruthy();
tick(1000);
- expect(preview.parentNode).toBeFalsy(
- 'Expected preview to be removed from the DOM at the end of the transform transition');
+ expect(preview.parentNode)
+ .withContext('Expected preview to be removed from the DOM at the end of the ' +
+ 'transform transition').toBeFalsy();
}));
it('should create a placeholder element while the item is dragged', fakeAsync(() => {
@@ -2729,17 +2773,20 @@ describe('CdkDrag', () => {
const placeholder = document.querySelector('.cdk-drag-placeholder')! as HTMLElement;
- expect(placeholder).toBeTruthy('Expected placeholder to be in the DOM');
+ expect(placeholder).withContext('Expected placeholder to be in the DOM').toBeTruthy();
expect(placeholder.parentNode)
- .toBe(initialParent, 'Expected placeholder to be inserted into the same parent');
+ .withContext('Expected placeholder to be inserted into the same parent')
+ .toBe(initialParent);
expect(placeholder.textContent!.trim())
- .toContain('One', 'Expected placeholder content to match element');
+ .withContext('Expected placeholder content to match element').toContain('One');
dispatchMouseEvent(document, 'mouseup');
fixture.detectChanges();
flush();
- expect(placeholder.parentNode).toBeFalsy('Expected placeholder to be removed from the DOM');
+ expect(placeholder.parentNode)
+ .withContext('Expected placeholder to be removed from the DOM')
+ .toBeFalsy();
}));
it('should insert the preview into the `body` if previewContainer is set to `global`',
@@ -3166,13 +3213,13 @@ describe('CdkDrag', () => {
dispatchMouseEvent(document, 'mousemove', targetRect.left, pointerTop);
fixture.detectChanges();
expect(getElementSibligsByPosition(placeholder, 'top').map(e => e.textContent!.trim()))
- .toEqual(['One', 'Zero', 'Two', 'Three'], 'Expected position to swap.');
+ .withContext('Expected position to swap.').toEqual(['One', 'Zero', 'Two', 'Three']);
// Move down a further 1px.
dispatchMouseEvent(document, 'mousemove', targetRect.left, pointerTop + 1);
fixture.detectChanges();
expect(getElementSibligsByPosition(placeholder, 'top').map(e => e.textContent!.trim()))
- .toEqual(['One', 'Zero', 'Two', 'Three'], 'Expected positions not to swap.');
+ .withContext('Expected positions not to swap.').toEqual(['One', 'Zero', 'Two', 'Three']);
dispatchMouseEvent(document, 'mouseup');
fixture.detectChanges();
@@ -3205,13 +3252,13 @@ describe('CdkDrag', () => {
dispatchMouseEvent(document, 'mousemove', targetRect.left, pointerTop);
fixture.detectChanges();
expect(getElementSibligsByPosition(placeholder, 'top').map(e => e.textContent!.trim()))
- .toEqual(['One', 'Zero', 'Two', 'Three'], 'Expected position to swap.');
+ .withContext('Expected position to swap.').toEqual(['One', 'Zero', 'Two', 'Three']);
// Move up 10px.
dispatchMouseEvent(document, 'mousemove', targetRect.left, pointerTop - 10);
fixture.detectChanges();
expect(getElementSibligsByPosition(placeholder, 'top').map(e => e.textContent!.trim()))
- .toEqual(['Zero', 'One', 'Two', 'Three'], 'Expected positions to swap again.');
+ .withContext('Expected positions to swap again.').toEqual(['Zero', 'One', 'Two', 'Three']);
dispatchMouseEvent(document, 'mouseup');
fixture.detectChanges();
@@ -3269,13 +3316,15 @@ describe('CdkDrag', () => {
const preview = document.querySelector('.cdk-drag-preview')! as HTMLElement;
- expect(preview.parentNode).toBeTruthy('Expected preview to be in the DOM');
- expect(item.parentNode).toBeTruthy('Expected drag item to be in the DOM');
+ expect(preview.parentNode).withContext('Expected preview to be in the DOM').toBeTruthy();
+ expect(item.parentNode).withContext('Expected drag item to be in the DOM').toBeTruthy();
fixture.destroy();
- expect(preview.parentNode).toBeFalsy('Expected preview to be removed from the DOM');
- expect(item.parentNode).toBeFalsy('Expected drag item to be removed from the DOM');
+ expect(preview.parentNode)
+ .withContext('Expected preview to be removed from the DOM').toBeFalsy();
+ expect(item.parentNode)
+ .withContext('Expected drag item to be removed from the DOM').toBeFalsy();
}));
it('should be able to customize the preview element', fakeAsync(() => {
@@ -3368,7 +3417,8 @@ describe('CdkDrag', () => {
const dragContainer = fixture.componentInstance.dropInstance.element.nativeElement;
const item = fixture.componentInstance.dragItems.toArray()[1].element.nativeElement;
- expect(dragContainer.contains(item)).toBe(true, 'Expected item to be in container.');
+ expect(dragContainer.contains(item))
+ .withContext('Expected item to be in container.').toBe(true);
// The coordinates don't matter.
dragElementViaMouse(fixture, item, 10, 10);
@@ -3376,7 +3426,7 @@ describe('CdkDrag', () => {
fixture.detectChanges();
expect(dragContainer.contains(item))
- .toBe(true, 'Expected item to be returned to container.');
+ .withContext('Expected item to be returned to container.').toBe(true);
}));
it('should position custom previews next to the pointer', fakeAsync(() => {
@@ -3774,7 +3824,7 @@ describe('CdkDrag', () => {
fixture.detectChanges();
expect(getElementIndexByPosition(placeholder, 'top'))
- .toBe(0, 'Expected placeholder to stay in place.');
+ .withContext('Expected placeholder to stay in place.').toBe(0);
dispatchMouseEvent(document, 'mouseup', targetX, targetY);
fixture.detectChanges();
@@ -3834,12 +3884,12 @@ describe('CdkDrag', () => {
startDraggingViaMouse(fixture, item.element.nativeElement);
expect(document.querySelectorAll('.cdk-drag-dragging').length)
- .toBe(1, 'Expected one item to be dragged initially.');
+ .withContext('Expected one item to be dragged initially.').toBe(1);
startDraggingViaMouse(fixture, otherItem.element.nativeElement);
expect(document.querySelectorAll('.cdk-drag-dragging').length)
- .toBe(1, 'Expected only one item to continue to be dragged.');
+ .withContext('Expected only one item to continue to be dragged.').toBe(1);
}));
it('should should be able to disable auto-scrolling', fakeAsync(() => {
@@ -4249,8 +4299,8 @@ describe('CdkDrag', () => {
startDraggingViaMouse(fixture, dragItems.first.element.nativeElement);
fixture.detectChanges();
- expect(innerClasses).toContain(draggingClass,
- 'Expected inner list to be dragging.');
+ expect(innerClasses)
+ .withContext('Expected inner list to be dragging.').toContain(draggingClass);
expect(outerClasses).not.toContain(draggingClass,
'Expected outer list to not be dragging.');
}));
@@ -4377,7 +4427,8 @@ describe('CdkDrag', () => {
let item = fixture.componentInstance.dragItems.first;
startDraggingViaMouse(fixture, item.element.nativeElement);
expect(document.querySelector('.cdk-drop-list-dragging'))
- .toBeTruthy('Expected to drag initially.');
+ .withContext('Expected to drag initially.')
+ .toBeTruthy();
fixture.componentInstance.items = [
{value: 'Five', height: ITEM_HEIGHT, margin: 0},
@@ -4387,13 +4438,15 @@ describe('CdkDrag', () => {
expect(fixture.componentInstance.droppedSpy).not.toHaveBeenCalled();
expect(document.querySelector('.cdk-drop-list-dragging'))
- .toBeFalsy('Expected not to be dragging after item is destroyed.');
+ .withContext('Expected not to be dragging after item is destroyed.')
+ .toBeFalsy();
item = fixture.componentInstance.dragItems.first;
startDraggingViaMouse(fixture, item.element.nativeElement);
expect(document.querySelector('.cdk-drop-list-dragging'))
- .toBeTruthy('Expected to be able to start a new drag sequence.');
+ .withContext('Expected to be able to start a new drag sequence.')
+ .toBeTruthy();
dispatchMouseEvent(document, 'mouseup');
fixture.detectChanges();
@@ -4494,32 +4547,32 @@ describe('CdkDrag', () => {
const preview = document.querySelector('.cdk-drag-preview') as HTMLElement;
const placeholder = fixture.nativeElement.querySelector('.cdk-drag-placeholder');
- expect(items.every(hasInitialTransform)).toBe(true,
- 'Expected items to preserve transform when dragging starts.');
- expect(hasInitialTransform(preview)).toBe(true,
- 'Expected preview to preserve transform when dragging starts.');
- expect(hasInitialTransform(placeholder)).toBe(true,
- 'Expected placeholder to preserve transform when dragging starts.');
+ expect(items.every(hasInitialTransform))
+ .withContext('Expected items to preserve transform when dragging starts.').toBe(true);
+ expect(hasInitialTransform(preview))
+ .withContext('Expected preview to preserve transform when dragging starts.').toBe(true);
+ expect(hasInitialTransform(placeholder))
+ .withContext('Expected placeholder to preserve transform when dragging starts.').toBe(true);
dispatchMouseEvent(document, 'mousemove', thirdItemRect.left + 1, thirdItemRect.top + 1);
fixture.detectChanges();
- expect(items.every(hasInitialTransform)).toBe(true,
- 'Expected items to preserve transform while dragging.');
- expect(hasInitialTransform(preview)).toBe(true,
- 'Expected preview to preserve transform while dragging.');
- expect(hasInitialTransform(placeholder)).toBe(true,
- 'Expected placeholder to preserve transform while dragging.');
+ expect(items.every(hasInitialTransform))
+ .withContext('Expected items to preserve transform while dragging.').toBe(true);
+ expect(hasInitialTransform(preview))
+ .withContext('Expected preview to preserve transform while dragging.').toBe(true);
+ expect(hasInitialTransform(placeholder))
+ .withContext('Expected placeholder to preserve transform while dragging.').toBe(true);
dispatchMouseEvent(document, 'mouseup');
fixture.detectChanges();
flush();
fixture.detectChanges();
- expect(items.every(hasInitialTransform)).toBe(true,
- 'Expected items to preserve transform when dragging stops.');
- expect(hasInitialTransform(preview)).toBe(true,
- 'Expected preview to preserve transform when dragging stops.');
- expect(hasInitialTransform(placeholder)).toBe(true,
- 'Expected placeholder to preserve transform when dragging stops.');
+ expect(items.every(hasInitialTransform))
+ .withContext('Expected items to preserve transform when dragging stops.').toBe(true);
+ expect(hasInitialTransform(preview))
+ .withContext('Expected preview to preserve transform when dragging stops.').toBe(true);
+ expect(hasInitialTransform(placeholder))
+ .withContext('Expected placeholder to preserve transform when dragging stops.').toBe(true);
}));
});
@@ -4571,19 +4624,19 @@ describe('CdkDrag', () => {
expect(placeholder).toBeTruthy();
expect(dropZones[0].contains(placeholder))
- .toBe(true, 'Expected placeholder to be inside the first container.');
+ .withContext('Expected placeholder to be inside the first container.').toBe(true);
dispatchMouseEvent(document, 'mousemove', targetRect.left + 1, targetRect.top + 1);
fixture.detectChanges();
expect(dropZones[1].contains(placeholder))
- .toBe(true, 'Expected placeholder to be inside second container.');
+ .withContext('Expected placeholder to be inside second container.').toBe(true);
dispatchMouseEvent(document, 'mousemove', initialRect.left + 1, initialRect.top + 1);
fixture.detectChanges();
expect(dropZones[0].contains(placeholder))
- .toBe(true, 'Expected placeholder to be back inside first container.');
+ .withContext('Expected placeholder to be back inside first container.').toBe(true);
dispatchMouseEvent(document, 'mouseup');
fixture.detectChanges();
@@ -4611,19 +4664,19 @@ describe('CdkDrag', () => {
expect(placeholder).toBeTruthy();
expect(dropZones[0].contains(placeholder))
- .toBe(true, 'Expected placeholder to be inside the first container.');
+ .withContext('Expected placeholder to be inside the first container.').toBe(true);
dispatchMouseEvent(document, 'mousemove', targetRect.left + 1, targetRect.top + 1);
fixture.detectChanges();
expect(dropZones[1].contains(placeholder))
- .toBe(true, 'Expected placeholder to be inside second container.');
+ .withContext('Expected placeholder to be inside second container.').toBe(true);
dispatchMouseEvent(document, 'mousemove', initialRect.left + 1, initialRect.top + 1);
fixture.detectChanges();
expect(dropZones[0].contains(placeholder))
- .toBe(true, 'Expected placeholder to be back inside first container.');
+ .withContext('Expected placeholder to be back inside first container.').toBe(true);
dispatchMouseEvent(document, 'mouseup');
fixture.detectChanges();
@@ -4786,19 +4839,19 @@ describe('CdkDrag', () => {
expect(placeholder).toBeTruthy();
expect(dropZones[0].contains(placeholder))
- .toBe(true, 'Expected placeholder to be inside the first container.');
+ .withContext('Expected placeholder to be inside the first container.').toBe(true);
dispatchMouseEvent(document, 'mousemove', targetRect.left + 1, targetRect.top + 1);
fixture.detectChanges();
expect(dropZones[1].contains(placeholder))
- .toBe(true, 'Expected placeholder to be inside second container.');
+ .withContext('Expected placeholder to be inside second container.').toBe(true);
dispatchMouseEvent(document, 'mousemove', initialRect.left + 1, initialRect.top + 1);
fixture.detectChanges();
expect(dropZones[0].contains(placeholder))
- .toBe(true, 'Expected placeholder to be back inside first container.');
+ .withContext('Expected placeholder to be back inside first container.').toBe(true);
dispatchMouseEvent(document, 'mouseup');
fixture.detectChanges();
@@ -4831,12 +4884,13 @@ describe('CdkDrag', () => {
fixture.detectChanges();
expect(targetElement.previousSibling === placeholder)
- .toBe(true, 'Expected placeholder to be inside second container before last item.');
+ .withContext('Expected placeholder to be inside second container before last item.')
+ .toBe(true);
// Update target rect
targetRect = targetElement.getBoundingClientRect();
expect(initialTargetZoneRect.bottom <= targetRect.top)
- .toBe(true, 'Expected target rect to be outside of initial target zone rect');
+ .withContext('Expected target rect to be outside of initial target zone rect').toBe(true);
// Swap with target
dispatchMouseEvent(document, 'mousemove', targetRect.left + 1, targetRect.bottom - 1);
@@ -4885,13 +4939,13 @@ describe('CdkDrag', () => {
expect(placeholder).toBeTruthy();
expect(dropZones[0].contains(placeholder))
- .toBe(true, 'Expected placeholder to be inside the first container.');
+ .withContext('Expected placeholder to be inside the first container.').toBe(true);
dispatchMouseEvent(document, 'mousemove', targetRect.left, targetRect.top);
fixture.detectChanges();
expect(dropZones[1].firstElementChild === placeholder)
- .toBe(true, 'Expected placeholder to be first child inside second container.');
+ .withContext('Expected placeholder to be first child inside second container.').toBe(true);
dispatchMouseEvent(document, 'mouseup');
}));
@@ -4922,13 +4976,13 @@ describe('CdkDrag', () => {
expect(placeholder).toBeTruthy();
expect(dropZones[0].contains(placeholder))
- .toBe(true, 'Expected placeholder to be inside the first container.');
+ .withContext('Expected placeholder to be inside the first container.').toBe(true);
dispatchMouseEvent(document, 'mousemove', targetRect.left, targetRect.top);
fixture.detectChanges();
expect(dropZones[1].lastChild === placeholder)
- .toBe(true, 'Expected placeholder to be last child inside second container.');
+ .withContext('Expected placeholder to be last child inside second container.').toBe(true);
dispatchMouseEvent(document, 'mouseup');
}));
@@ -5072,10 +5126,11 @@ describe('CdkDrag', () => {
const dropContainers = fixture.componentInstance.dropInstances
.map(drop => drop.element.nativeElement);
- expect(dropContainers[0].contains(item.element.nativeElement)).toBe(true,
- 'Expected DOM element to be in first container');
- expect(item.dropContainer).toBe(fixture.componentInstance.dropInstances.first,
- 'Expected CdkDrag to be in first container in memory');
+ expect(dropContainers[0].contains(item.element.nativeElement))
+ .withContext('Expected DOM element to be in first container').toBe(true);
+ expect(item.dropContainer)
+ .withContext('Expected CdkDrag to be in first container in memory')
+ .toBe(fixture.componentInstance.dropInstances.first);
dragElementViaMouse(fixture, item.element.nativeElement,
targetRect.left + 1, targetRect.top + 1);
@@ -5097,10 +5152,11 @@ describe('CdkDrag', () => {
dropPoint: {x: jasmine.any(Number), y: jasmine.any(Number)}
});
- expect(dropContainers[0].contains(item.element.nativeElement)).toBe(true,
- 'Expected DOM element to be returned to first container');
- expect(item.dropContainer).toBe(fixture.componentInstance.dropInstances.first,
- 'Expected CdkDrag to be returned to first container in memory');
+ expect(dropContainers[0].contains(item.element.nativeElement))
+ .withContext('Expected DOM element to be returned to first container').toBe(true);
+ expect(item.dropContainer)
+ .withContext('Expected CdkDrag to be returned to first container in memory')
+ .toBe(fixture.componentInstance.dropInstances.first);
}));
it('should be able to return an element to its initial container in the same sequence, ' +
@@ -5126,19 +5182,19 @@ describe('CdkDrag', () => {
expect(placeholder).toBeTruthy();
expect(dropZones[0].contains(placeholder))
- .toBe(true, 'Expected placeholder to be inside the first container.');
+ .withContext('Expected placeholder to be inside the first container.').toBe(true);
dispatchMouseEvent(document, 'mousemove', targetRect.left + 1, targetRect.top + 1);
fixture.detectChanges();
expect(dropZones[1].contains(placeholder))
- .toBe(true, 'Expected placeholder to be inside second container.');
+ .withContext('Expected placeholder to be inside second container.').toBe(true);
dispatchMouseEvent(document, 'mousemove', initialRect.left + 1, initialRect.top + 1);
fixture.detectChanges();
expect(dropZones[0].contains(placeholder))
- .toBe(true, 'Expected placeholder to be back inside first container.');
+ .withContext('Expected placeholder to be back inside first container.').toBe(true);
dispatchMouseEvent(document, 'mouseup');
fixture.detectChanges();
@@ -5205,7 +5261,7 @@ describe('CdkDrag', () => {
const item = fixture.componentInstance.groupedDragItems[0][1];
expect(dropZones.every(c => !c.classList.contains('cdk-drop-list-receiving')))
- .toBe(true, 'Expected neither of the containers to have the class.');
+ .withContext('Expected neither of the containers to have the class.').toBe(true);
startDraggingViaMouse(fixture, item.element.nativeElement);
fixture.detectChanges();
@@ -5216,9 +5272,8 @@ describe('CdkDrag', () => {
'Expected source container not to have the receiving class.');
expect(dropZones[1].classList)
- .toContain(
- 'cdk-drop-list-receiving',
- 'Expected target container to have the receiving class.');
+ .withContext('Expected target container to have the receiving class.')
+ .toContain('cdk-drop-list-receiving');
}));
it('should toggle the `receiving` class when the item enters a new list', fakeAsync(() => {
@@ -5232,7 +5287,7 @@ describe('CdkDrag', () => {
const targetRect = groups[1][2].element.nativeElement.getBoundingClientRect();
expect(dropZones.every(c => !c.classList.contains('cdk-drop-list-receiving')))
- .toBe(true, 'Expected neither of the containers to have the class.');
+ .withContext('Expected neither of the containers to have the class.').toBe(true);
startDraggingViaMouse(fixture, item.element.nativeElement);
@@ -5242,22 +5297,19 @@ describe('CdkDrag', () => {
'Expected source container not to have the receiving class.');
expect(dropZones[1].classList)
- .toContain(
- 'cdk-drop-list-receiving',
- 'Expected target container to have the receiving class.');
+ .withContext('Expected target container to have the receiving class.')
+ .toContain('cdk-drop-list-receiving');
dispatchMouseEvent(document, 'mousemove', targetRect.left + 1, targetRect.top + 1);
fixture.detectChanges();
expect(dropZones[0].classList)
- .toContain(
- 'cdk-drop-list-receiving',
- 'Expected old container to have the receiving class after exiting.');
+ .withContext('Expected old container to have the receiving class after exiting.')
+ .toContain('cdk-drop-list-receiving');
- expect(dropZones[1].classList)
- .not.toContain(
- 'cdk-drop-list-receiving',
- 'Expected new container not to have the receiving class after exiting.');
+ expect(dropZones[1].classList).not
+ .withContext('Expected new container not to have the receiving class after exiting.')
+ .toContain('cdk-drop-list-receiving');
}));
it('should not set the receiving class if the item does not match the enter predicate',
@@ -5271,13 +5323,13 @@ describe('CdkDrag', () => {
const item = fixture.componentInstance.groupedDragItems[0][1];
expect(dropZones.every(c => !c.classList.contains('cdk-drop-list-receiving')))
- .toBe(true, 'Expected neither of the containers to have the class.');
+ .withContext('Expected neither of the containers to have the class.').toBe(true);
startDraggingViaMouse(fixture, item.element.nativeElement);
fixture.detectChanges();
expect(dropZones.every(c => !c.classList.contains('cdk-drop-list-receiving')))
- .toBe(true, 'Expected neither of the containers to have the class.');
+ .withContext('Expected neither of the containers to have the class.').toBe(true);
}));
it('should set the receiving class on the source container, even if the enter predicate ' +
@@ -5293,27 +5345,24 @@ describe('CdkDrag', () => {
const targetRect = groups[1][2].element.nativeElement.getBoundingClientRect();
expect(dropZones.every(c => !c.classList.contains('cdk-drop-list-receiving')))
- .toBe(true, 'Expected neither of the containers to have the class.');
+ .withContext('Expected neither of the containers to have the class.').toBe(true);
startDraggingViaMouse(fixture, item.element.nativeElement);
- expect(dropZones[0].classList)
- .not.toContain(
- 'cdk-drop-list-receiving',
- 'Expected source container not to have the receiving class.');
+ expect(dropZones[0].classList).not
+ .withContext('Expected source container not to have the receiving class.')
+ .toContain('cdk-drop-list-receiving');
expect(dropZones[1].classList)
- .toContain(
- 'cdk-drop-list-receiving',
- 'Expected target container to have the receiving class.');
+ .withContext('Expected target container to have the receiving class.')
+ .toContain('cdk-drop-list-receiving');
dispatchMouseEvent(document, 'mousemove', targetRect.left + 1, targetRect.top + 1);
fixture.detectChanges();
expect(dropZones[0].classList)
- .toContain(
- 'cdk-drop-list-receiving',
- 'Expected old container to have the receiving class after exiting.');
+ .withContext('Expected old container to have the receiving class after exiting.')
+ .toContain('cdk-drop-list-receiving');
expect(dropZones[1].classList)
.not.toContain(
@@ -5344,20 +5393,20 @@ describe('CdkDrag', () => {
expect(placeholder).toBeTruthy();
expect(dropZones[0].contains(placeholder))
- .toBe(true, 'Expected placeholder to be inside the first container.');
+ .withContext('Expected placeholder to be inside the first container.').toBe(true);
dispatchMouseEvent(document, 'mousemove',
intermediateRect.left + 1, intermediateRect.top + 1);
fixture.detectChanges();
expect(dropZones[1].contains(placeholder))
- .toBe(true, 'Expected placeholder to be inside second container.');
+ .withContext('Expected placeholder to be inside second container.').toBe(true);
dispatchMouseEvent(document, 'mousemove', finalRect.left + 1, finalRect.top + 1);
fixture.detectChanges();
expect(dropZones[2].contains(placeholder))
- .toBe(true, 'Expected placeholder to be inside third container.');
+ .withContext('Expected placeholder to be inside third container.').toBe(true);
dispatchMouseEvent(document, 'mouseup');
fixture.detectChanges();
@@ -5403,20 +5452,20 @@ describe('CdkDrag', () => {
expect(placeholder).toBeTruthy();
expect(dropZones[0].contains(placeholder))
- .toBe(true, 'Expected placeholder to be inside the first container.');
+ .withContext('Expected placeholder to be inside the first container.').toBe(true);
dispatchMouseEvent(document, 'mousemove',
intermediateRect.left + 1, intermediateRect.top + 1);
fixture.detectChanges();
expect(dropZones[1].contains(placeholder))
- .toBe(true, 'Expected placeholder to be inside second container.');
+ .withContext('Expected placeholder to be inside second container.').toBe(true);
dispatchMouseEvent(document, 'mousemove', finalRect.left + 1, finalRect.top + 1);
fixture.detectChanges();
expect(dropZones[1].contains(placeholder))
- .toBe(true, 'Expected placeholder to remain in the second container.');
+ .withContext('Expected placeholder to remain in the second container.').toBe(true);
dispatchMouseEvent(document, 'mouseup');
fixture.detectChanges();
@@ -5454,17 +5503,17 @@ describe('CdkDrag', () => {
expect(placeholder).toBeTruthy();
expect(dropZones[0].contains(placeholder))
- .toBe(true, 'Expected placeholder to be inside the first container.');
+ .withContext('Expected placeholder to be inside the first container.').toBe(true);
expect(getElementIndexByPosition(placeholder, 'top'))
- .toBe(1, 'Expected placeholder to be at item index.');
+ .withContext('Expected placeholder to be at item index.').toBe(1);
dispatchMouseEvent(document, 'mousemove', targetRect.left + 1, targetRect.top + 1);
fixture.detectChanges();
expect(dropZones[1].contains(placeholder))
- .toBe(true, 'Expected placeholder to be inside second container.');
+ .withContext('Expected placeholder to be inside second container.').toBe(true);
expect(getElementIndexByPosition(placeholder, 'top'))
- .toBe(3, 'Expected placeholder to be at the target index.');
+ .withContext('Expected placeholder to be at the target index.').toBe(3);
const firstInitialSiblingRect = groups[0][0].element
.nativeElement.getBoundingClientRect();
@@ -5475,9 +5524,9 @@ describe('CdkDrag', () => {
fixture.detectChanges();
expect(dropZones[0].contains(placeholder))
- .toBe(true, 'Expected placeholder to be back inside first container.');
+ .withContext('Expected placeholder to be back inside first container.').toBe(true);
expect(getElementIndexByPosition(placeholder, 'top'))
- .toBe(1, 'Expected placeholder to be back at the initial index.');
+ .withContext('Expected placeholder to be back at the initial index.').toBe(1);
dispatchMouseEvent(document, 'mouseup');
fixture.detectChanges();
@@ -5503,17 +5552,17 @@ describe('CdkDrag', () => {
expect(placeholder).toBeTruthy();
expect(dropZones[0].contains(placeholder))
- .toBe(true, 'Expected placeholder to be inside the first container.');
+ .withContext('Expected placeholder to be inside the first container.').toBe(true);
expect(getElementIndexByPosition(placeholder, 'top'))
- .toBe(1, 'Expected placeholder to be at item index.');
+ .withContext('Expected placeholder to be at item index.').toBe(1);
dispatchMouseEvent(document, 'mousemove', targetRect.left + 1, targetRect.top + 1);
fixture.detectChanges();
expect(dropZones[1].contains(placeholder))
- .toBe(true, 'Expected placeholder to be inside second container.');
+ .withContext('Expected placeholder to be inside second container.').toBe(true);
expect(getElementIndexByPosition(placeholder, 'top'))
- .toBe(3, 'Expected placeholder to be at the target index.');
+ .withContext('Expected placeholder to be at the target index.').toBe(3);
const nextTargetRect = groups[0][3].element.nativeElement.getBoundingClientRect();
@@ -5522,9 +5571,9 @@ describe('CdkDrag', () => {
fixture.detectChanges();
expect(dropZones[0].contains(placeholder))
- .toBe(true, 'Expected placeholder to be back inside first container.');
+ .withContext('Expected placeholder to be back inside first container.').toBe(true);
expect(getElementIndexByPosition(placeholder, 'top'))
- .toBe(2, 'Expected placeholder to be at the index at which it entered.');
+ .withContext('Expected placeholder to be at the index at which it entered.').toBe(2);
}));
it('should toggle a class when dragging an item inside a wrapper component component ' +
@@ -5550,25 +5599,21 @@ describe('CdkDrag', () => {
startDraggingViaMouse(fixture, item);
expect(startZone.classList)
- .toContain(
- 'cdk-drop-list-dragging',
- 'Expected start to have dragging class after dragging has started.');
- expect(targetZone.classList)
- .not.toContain(
- 'cdk-drop-list-dragging',
- 'Expected target not to have dragging class after dragging has started.');
+ .withContext('Expected start to have dragging class after dragging has started.')
+ .toContain('cdk-drop-list-dragging');
+ expect(targetZone.classList).not
+ .withContext('Expected target not to have dragging class after dragging has started.')
+ .toContain('cdk-drop-list-dragging');
dispatchMouseEvent(document, 'mousemove', targetRect.left + 1, targetRect.top + 1);
fixture.detectChanges();
- expect(startZone.classList)
- .not.toContain(
- 'cdk-drop-list-dragging',
- 'Expected start not to have dragging class once item has been moved over.');
+ expect(startZone.classList).not
+ .withContext('Expected start not to have dragging class once item has been moved over.')
+ .toContain('cdk-drop-list-dragging');
expect(targetZone.classList)
- .toContain(
- 'cdk-drop-list-dragging',
- 'Expected target to have dragging class once item has been moved over.');
+ .withContext('Expected target to have dragging class once item has been moved over.')
+ .toContain('cdk-drop-list-dragging');
}));
it('should dispatch an event when an item enters a new container', fakeAsync(() => {
@@ -5787,12 +5832,12 @@ describe('CdkDrag', () => {
startDraggingViaMouse(fixture, item.element.nativeElement);
expect(document.querySelectorAll('.cdk-drag-dragging').length)
- .toBe(1, 'Expected one item to be dragged initially.');
+ .withContext('Expected one item to be dragged initially.').toBe(1);
startDraggingViaMouse(fixture, itemInOtherList.element.nativeElement);
expect(document.querySelectorAll('.cdk-drag-dragging').length)
- .toBe(1, 'Expected only one item to continue to be dragged.');
+ .withContext('Expected only one item to continue to be dragged.').toBe(1);
}));
it('should insert the preview inside the shadow root by default', fakeAsync(() => {
diff --git a/src/cdk/overlay/dispatchers/overlay-keyboard-dispatcher.spec.ts b/src/cdk/overlay/dispatchers/overlay-keyboard-dispatcher.spec.ts
index c1a3fae2c5f6..ff079789fcb0 100644
--- a/src/cdk/overlay/dispatchers/overlay-keyboard-dispatcher.spec.ts
+++ b/src/cdk/overlay/dispatchers/overlay-keyboard-dispatcher.spec.ts
@@ -35,18 +35,20 @@ describe('OverlayKeyboardDispatcher', () => {
keyboardDispatcher.add(overlayTwo);
expect(keyboardDispatcher._attachedOverlays.length)
- .toBe(2, 'Expected both overlays to be tracked.');
- expect(keyboardDispatcher._attachedOverlays[0]).toBe(overlayOne, 'Expected one to be first.');
- expect(keyboardDispatcher._attachedOverlays[1]).toBe(overlayTwo, 'Expected two to be last.');
+ .withContext('Expected both overlays to be tracked.').toBe(2);
+ expect(keyboardDispatcher._attachedOverlays[0])
+ .withContext('Expected one to be first.').toBe(overlayOne);
+ expect(keyboardDispatcher._attachedOverlays[1])
+ .withContext('Expected two to be last.').toBe(overlayTwo);
// Detach first one and re-attach it
keyboardDispatcher.remove(overlayOne);
keyboardDispatcher.add(overlayOne);
expect(keyboardDispatcher._attachedOverlays[0])
- .toBe(overlayTwo, 'Expected two to now be first.');
+ .withContext('Expected two to now be first.').toBe(overlayTwo);
expect(keyboardDispatcher._attachedOverlays[1])
- .toBe(overlayOne, 'Expected one to now be last.');
+ .withContext('Expected one to now be last.').toBe(overlayOne);
});
it('should dispatch body keyboard events to the most recently attached overlay', () => {
diff --git a/src/cdk/overlay/dispatchers/overlay-outside-click-dispatcher.spec.ts b/src/cdk/overlay/dispatchers/overlay-outside-click-dispatcher.spec.ts
index c9211a2568f7..c2afceebfacd 100644
--- a/src/cdk/overlay/dispatchers/overlay-outside-click-dispatcher.spec.ts
+++ b/src/cdk/overlay/dispatchers/overlay-outside-click-dispatcher.spec.ts
@@ -33,19 +33,19 @@ describe('OverlayOutsideClickDispatcher', () => {
outsideClickDispatcher.add(overlayTwo);
expect(outsideClickDispatcher._attachedOverlays.length)
- .toBe(2, 'Expected both overlays to be tracked.');
+ .withContext('Expected both overlays to be tracked.').toBe(2);
expect(outsideClickDispatcher._attachedOverlays[0])
- .toBe(overlayOne, 'Expected one to be first.');
+ .withContext('Expected one to be first.').toBe(overlayOne);
expect(outsideClickDispatcher._attachedOverlays[1])
- .toBe(overlayTwo, 'Expected two to be last.');
+ .withContext('Expected two to be last.').toBe(overlayTwo);
outsideClickDispatcher.remove(overlayOne);
outsideClickDispatcher.add(overlayOne);
expect(outsideClickDispatcher._attachedOverlays[0])
- .toBe(overlayTwo, 'Expected two to now be first.');
+ .withContext('Expected two to now be first.').toBe(overlayTwo);
expect(outsideClickDispatcher._attachedOverlays[1])
- .toBe(overlayOne, 'Expected one to now be last.');
+ .withContext('Expected one to now be last.').toBe(overlayOne);
overlayOne.dispose();
overlayTwo.dispose();
diff --git a/src/cdk/overlay/overlay-container.spec.ts b/src/cdk/overlay/overlay-container.spec.ts
index 789236099590..540c43ab6f87 100644
--- a/src/cdk/overlay/overlay-container.spec.ts
+++ b/src/cdk/overlay/overlay-container.spec.ts
@@ -29,15 +29,17 @@ describe('OverlayContainer', () => {
overlayRef.attach(fixture.componentInstance.templatePortal);
fixture.detectChanges();
- expect(document.querySelector('.cdk-overlay-container'))
- .not.toBeNull('Expected the overlay container to be in the DOM after opening an overlay');
+ expect(document.querySelector('.cdk-overlay-container')).not
+ .withContext('Expected the overlay container to be in the DOM after opening an overlay')
+ .toBeNull();
// Manually call `ngOnDestroy` because there is no way to force Angular to destroy an
// injectable in a unit test.
overlayContainer.ngOnDestroy();
expect(document.querySelector('.cdk-overlay-container'))
- .toBeNull('Expected the overlay container *not* to be in the DOM after destruction');
+ .withContext('Expected the overlay container *not* to be in the DOM after destruction')
+ .toBeNull();
});
it('should add and remove css classes from the container element', () => {
@@ -45,12 +47,13 @@ describe('OverlayContainer', () => {
const containerElement = document.querySelector('.cdk-overlay-container')!;
expect(containerElement.classList.contains('commander-shepard'))
- .toBe(true, 'Expected the overlay container to have class "commander-shepard"');
+ .withContext('Expected the overlay container to have class "commander-shepard"').toBe(true);
overlayContainer.getContainerElement().classList.remove('commander-shepard');
expect(containerElement.classList.contains('commander-shepard'))
- .toBe(false, 'Expected the overlay container not to have class "commander-shepard"');
+ .withContext('Expected the overlay container not to have class "commander-shepard"')
+ .toBe(false);
});
it('should remove overlay containers from the server when on the browser', () => {
diff --git a/src/cdk/overlay/overlay-directives.spec.ts b/src/cdk/overlay/overlay-directives.spec.ts
index 073b3cd84a2d..8f3762649f97 100644
--- a/src/cdk/overlay/overlay-directives.spec.ts
+++ b/src/cdk/overlay/overlay-directives.spec.ts
@@ -115,7 +115,8 @@ describe('Overlay directives', () => {
expect(overlayContainerElement.textContent!.trim()).toBe('');
expect(getPaneElement())
- .toBeFalsy('Expected the overlay pane element to be removed when disposed.');
+ .withContext('Expected the overlay pane element to be removed when disposed.')
+ .toBeFalsy();
});
it('should use a connected position strategy with a default set of positions', () => {
@@ -162,8 +163,8 @@ describe('Overlay directives', () => {
const event = dispatchKeyboardEvent(document.body, 'keydown', ESCAPE);
fixture.detectChanges();
- expect(overlayContainerElement.textContent!.trim()).toBe('',
- 'Expected overlay to have been detached.');
+ expect(overlayContainerElement.textContent!.trim())
+ .withContext('Expected overlay to have been detached.').toBe('');
expect(event.defaultPrevented).toBe(true);
});
@@ -614,7 +615,8 @@ describe('Overlay directives', () => {
const latestCall = fixture.componentInstance.positionChangeHandler.calls.mostRecent();
expect(latestCall.args[0] instanceof ConnectedOverlayPositionChange)
- .toBe(true, `Expected directive to emit an instance of ConnectedOverlayPositionChange.`);
+ .withContext(`Expected directive to emit an instance of ConnectedOverlayPositionChange.`)
+ .toBe(true);
});
it('should emit when attached', () => {
@@ -624,7 +626,8 @@ describe('Overlay directives', () => {
expect(fixture.componentInstance.attachHandler).toHaveBeenCalled();
expect(fixture.componentInstance.attachResult instanceof HTMLElement)
- .toBe(true, `Expected pane to be populated with HTML elements when attach was called.`);
+ .withContext(`Expected pane to be populated with HTML elements when attach was called.`)
+ .toBe(true);
fixture.componentInstance.isOpen = false;
fixture.detectChanges();
diff --git a/src/cdk/overlay/overlay.spec.ts b/src/cdk/overlay/overlay.spec.ts
index dd04316f6a73..bd20090d7a7b 100644
--- a/src/cdk/overlay/overlay.spec.ts
+++ b/src/cdk/overlay/overlay.spec.ts
@@ -123,13 +123,14 @@ describe('Overlay', () => {
expect(paneElement.childNodes.length).not.toBe(0);
expect(paneElement.style.pointerEvents)
- .toBe('', 'Expected the overlay pane to enable pointerEvents when attached.');
+ .withContext('Expected the overlay pane to enable pointerEvents when attached.').toBe('');
overlayRef.detach();
expect(paneElement.childNodes.length).toBe(0);
expect(paneElement.style.pointerEvents)
- .toBe('none', 'Expected the overlay pane to disable pointerEvents when detached.');
+ .withContext('Expected the overlay pane to disable pointerEvents when detached.')
+ .toBe('none');
});
it('should open multiple overlays', () => {
@@ -160,9 +161,11 @@ describe('Overlay', () => {
cakeOverlayRef.attach(templatePortal);
expect(pizzaOverlayRef.hostElement.nextSibling)
- .toBeTruthy('Expected pizza to be on the bottom.');
+ .withContext('Expected pizza to be on the bottom.')
+ .toBeTruthy();
expect(cakeOverlayRef.hostElement.nextSibling)
- .toBeFalsy('Expected cake to be on top.');
+ .withContext('Expected cake to be on top.')
+ .toBeFalsy();
pizzaOverlayRef.dispose();
cakeOverlayRef.detach();
@@ -172,9 +175,11 @@ describe('Overlay', () => {
cakeOverlayRef.attach(templatePortal);
expect(pizzaOverlayRef.hostElement.nextSibling)
- .toBeTruthy('Expected pizza to still be on the bottom.');
+ .withContext('Expected pizza to still be on the bottom.')
+ .toBeTruthy();
expect(cakeOverlayRef.hostElement.nextSibling)
- .toBeFalsy('Expected cake to still be on top.');
+ .withContext('Expected cake to still be on top.')
+ .toBeFalsy();
}));
it('should take the default direction from the global Directionality', () => {
@@ -210,10 +215,12 @@ describe('Overlay', () => {
overlayRef.attachments().subscribe(() => {
expect(overlayContainerElement.querySelector('pizza'))
- .toBeTruthy('Expected the overlay to have been attached.');
+ .withContext('Expected the overlay to have been attached.')
+ .toBeTruthy();
expect(overlayContainerElement.querySelector('.cdk-overlay-backdrop'))
- .toBeTruthy('Expected the backdrop to have been attached.');
+ .withContext('Expected the backdrop to have been attached.')
+ .toBeTruthy();
});
overlayRef.attach(componentPortal);
@@ -255,7 +262,8 @@ describe('Overlay', () => {
overlayRef.detachments().subscribe(() => {
expect(overlayContainerElement.querySelector('pizza'))
- .toBeFalsy('Expected the overlay to have been detached.');
+ .withContext('Expected the overlay to have been detached.')
+ .toBeFalsy();
});
overlayRef.attach(componentPortal);
@@ -306,16 +314,25 @@ describe('Overlay', () => {
const overlayRef = overlay.create({hasBackdrop: true});
overlayRef.attach(componentPortal);
- expect(overlayRef.hostElement).toBeTruthy('Expected overlay host to be defined.');
- expect(overlayRef.overlayElement).toBeTruthy('Expected overlay element to be defined.');
- expect(overlayRef.backdropElement).toBeTruthy('Expected backdrop element to be defined.');
+ expect(overlayRef.hostElement)
+ .withContext('Expected overlay host to be defined.')
+ .toBeTruthy();
+ expect(overlayRef.overlayElement)
+ .withContext('Expected overlay element to be defined.')
+ .toBeTruthy();
+ expect(overlayRef.backdropElement)
+ .withContext('Expected backdrop element to be defined.')
+ .toBeTruthy();
overlayRef.dispose();
tick(500);
- expect(overlayRef.hostElement).toBeFalsy('Expected overlay host not to be referenced.');
- expect(overlayRef.overlayElement).toBeFalsy('Expected overlay element not to be referenced.');
- expect(overlayRef.backdropElement).toBeFalsy('Expected backdrop element not to be referenced.');
+ expect(overlayRef.hostElement)
+ .withContext('Expected overlay host not to be referenced.').toBeFalsy();
+ expect(overlayRef.overlayElement)
+ .withContext('Expected overlay element not to be referenced.').toBeFalsy();
+ expect(overlayRef.backdropElement)
+ .withContext('Expected backdrop element not to be referenced.').toBeFalsy();
}));
it('should clear the backdrop timeout if the transition finishes first', fakeAsync(() => {
@@ -374,24 +391,28 @@ describe('Overlay', () => {
viewContainerFixture.detectChanges();
expect(overlayRef.hostElement.parentElement)
- .toBeTruthy('Expected host element to be in the DOM.');
+ .withContext('Expected host element to be in the DOM.')
+ .toBeTruthy();
overlayRef.detach();
expect(overlayRef.hostElement.parentElement)
- .toBeTruthy('Expected host element not to have been removed immediately.');
+ .withContext('Expected host element not to have been removed immediately.')
+ .toBeTruthy();
viewContainerFixture.detectChanges();
zone.simulateZoneExit();
expect(overlayRef.hostElement.parentElement)
- .toBeFalsy('Expected host element to have been removed once the zone stabilizes.');
+ .withContext('Expected host element to have been removed once the zone stabilizes.')
+ .toBeFalsy();
overlayRef.attach(componentPortal);
viewContainerFixture.detectChanges();
expect(overlayRef.hostElement.parentElement)
- .toBeTruthy('Expected host element to be back in the DOM.');
+ .withContext('Expected host element to be back in the DOM.')
+ .toBeTruthy();
});
it('should be able to dispose an overlay on navigation', () => {
@@ -414,7 +435,8 @@ describe('Overlay', () => {
.not.toContain('custom-class-one', 'Expected class to be initially missing');
overlayRef.addPanelClass('custom-class-one');
- expect(pane.classList).toContain('custom-class-one', 'Expected class to be added');
+ expect(pane.classList)
+ .withContext('Expected class to be added').toContain('custom-class-one');
overlayRef.removePanelClass('custom-class-one');
expect(pane.classList).not.toContain('custom-class-one', 'Expected class to be removed');
@@ -463,7 +485,8 @@ describe('Overlay', () => {
const overlayRef = overlay.create(config);
overlayRef.attach(componentPortal);
- expect(overlayPresentInDom).toBeTruthy('Expected host element to be attached to the DOM.');
+ expect(overlayPresentInDom)
+ .withContext('Expected host element to be attached to the DOM.').toBeTruthy();
overlayRef.detach();
zone.simulateZoneExit();
@@ -471,7 +494,8 @@ describe('Overlay', () => {
overlayRef.attach(componentPortal);
- expect(overlayPresentInDom).toBeTruthy('Expected host element to be attached to the DOM.');
+ expect(overlayPresentInDom)
+ .withContext('Expected host element to be attached to the DOM.').toBeTruthy();
}));
it('should not apply the position if it detaches before the zone stabilizes', fakeAsync(() => {
@@ -780,7 +804,8 @@ describe('Overlay', () => {
expect(children.indexOf(backdrop)).toBeGreaterThan(-1);
expect(children.indexOf(host)).toBeGreaterThan(-1);
expect(children.indexOf(backdrop))
- .toBeLessThan(children.indexOf(host), 'Expected backdrop to be before the host in the DOM');
+ .withContext('Expected backdrop to be before the host in the DOM')
+ .toBeLessThan(children.indexOf(host));
});
it('should remove the event listener from the backdrop', () => {
@@ -840,7 +865,8 @@ describe('Overlay', () => {
viewContainerFixture.detectChanges();
const pane = overlayContainerElement.querySelector('.cdk-overlay-pane') as HTMLElement;
- expect(pane.classList).toContain('custom-panel-class', 'Expected class to be added');
+ expect(pane.classList)
+ .withContext('Expected class to be added').toContain('custom-panel-class');
overlayRef.detach();
zone.simulateZoneExit();
@@ -849,7 +875,8 @@ describe('Overlay', () => {
overlayRef.attach(componentPortal);
viewContainerFixture.detectChanges();
- expect(pane.classList).toContain('custom-panel-class', 'Expected class to be re-added');
+ expect(pane.classList)
+ .withContext('Expected class to be re-added').toContain('custom-panel-class');
});
it('should wait for the overlay to be detached before removing the panelClass', () => {
@@ -860,18 +887,21 @@ describe('Overlay', () => {
viewContainerFixture.detectChanges();
const pane = overlayContainerElement.querySelector('.cdk-overlay-pane') as HTMLElement;
- expect(pane.classList).toContain('custom-panel-class', 'Expected class to be added');
+ expect(pane.classList)
+ .withContext('Expected class to be added').toContain('custom-panel-class');
overlayRef.detach();
viewContainerFixture.detectChanges();
expect(pane.classList)
- .toContain('custom-panel-class', 'Expected class not to be removed immediately');
+ .withContext('Expected class not to be removed immediately')
+ .toContain('custom-panel-class');
zone.simulateZoneExit();
- expect(pane.classList)
- .not.toContain('custom-panel-class', 'Expected class to be removed on stable');
+ expect(pane.classList).not
+ .withContext('Expected class to be removed on stable')
+ .toContain('custom-panel-class');
});
@@ -883,8 +913,9 @@ describe('Overlay', () => {
const config = new OverlayConfig({scrollStrategy: fakeScrollStrategy});
const overlayRef = overlay.create(config);
- expect(fakeScrollStrategy.overlayRef).toBe(overlayRef,
- 'Expected scroll strategy to have been attached to the current overlay ref.');
+ expect(fakeScrollStrategy.overlayRef)
+ .withContext('Expected scroll strategy to have been attached to the current overlay ref.')
+ .toBe(overlayRef);
});
it('should enable the scroll strategy when the overlay is attached', () => {
@@ -893,7 +924,8 @@ describe('Overlay', () => {
const overlayRef = overlay.create(config);
overlayRef.attach(componentPortal);
- expect(fakeScrollStrategy.isEnabled).toBe(true, 'Expected scroll strategy to be enabled.');
+ expect(fakeScrollStrategy.isEnabled)
+ .withContext('Expected scroll strategy to be enabled.').toBe(true);
});
it('should disable the scroll strategy once the overlay is detached', () => {
@@ -902,10 +934,12 @@ describe('Overlay', () => {
const overlayRef = overlay.create(config);
overlayRef.attach(componentPortal);
- expect(fakeScrollStrategy.isEnabled).toBe(true, 'Expected scroll strategy to be enabled.');
+ expect(fakeScrollStrategy.isEnabled)
+ .withContext('Expected scroll strategy to be enabled.').toBe(true);
overlayRef.detach();
- expect(fakeScrollStrategy.isEnabled).toBe(false, 'Expected scroll strategy to be disabled.');
+ expect(fakeScrollStrategy.isEnabled)
+ .withContext('Expected scroll strategy to be disabled.').toBe(false);
});
it('should disable the scroll strategy when the overlay is destroyed', () => {
@@ -914,7 +948,8 @@ describe('Overlay', () => {
const overlayRef = overlay.create(config);
overlayRef.dispose();
- expect(fakeScrollStrategy.isEnabled).toBe(false, 'Expected scroll strategy to be disabled.');
+ expect(fakeScrollStrategy.isEnabled)
+ .withContext('Expected scroll strategy to be disabled.').toBe(false);
});
it('should detach the scroll strategy when the overlay is destroyed', () => {
diff --git a/src/cdk/overlay/position/flexible-connected-position-strategy.spec.ts b/src/cdk/overlay/position/flexible-connected-position-strategy.spec.ts
index c5a1a47ad11d..3d6ac360b98a 100644
--- a/src/cdk/overlay/position/flexible-connected-position-strategy.spec.ts
+++ b/src/cdk/overlay/position/flexible-connected-position-strategy.spec.ts
@@ -405,8 +405,9 @@ describe('FlexibleConnectedPositionStrategy', () => {
positionStrategy.reapplyLastPosition();
const overlayRect = overlayRef.overlayElement.getBoundingClientRect();
- expect(Math.floor(overlayRect.bottom)).toBe(Math.floor(originRect.top),
- 'Expected overlay to be re-aligned to the trigger in the previous position.');
+ expect(Math.floor(overlayRect.bottom))
+ .withContext('Expected overlay to be re-aligned to the trigger in the previous position.')
+ .toBe(Math.floor(originRect.top));
});
it('should default to the initial position, if no positions fit in the viewport', () => {
@@ -427,8 +428,9 @@ describe('FlexibleConnectedPositionStrategy', () => {
positionStrategy.reapplyLastPosition();
const overlayRect = overlayRef.overlayElement.getBoundingClientRect();
- expect(Math.floor(overlayRect.bottom)).toBe(Math.floor(originRect.top),
- 'Expected overlay to be re-aligned to the trigger in the initial position.');
+ expect(Math.floor(overlayRect.bottom))
+ .withContext('Expected overlay to be re-aligned to the trigger in the initial position.')
+ .toBe(Math.floor(originRect.top));
});
it('should position a panel properly when rtl', () => {
@@ -878,7 +880,8 @@ describe('FlexibleConnectedPositionStrategy', () => {
expect(positionChangeHandler).toHaveBeenCalled();
expect(latestCall.args[0] instanceof ConnectedOverlayPositionChange)
- .toBe(true, `Expected strategy to emit an instance of ConnectedOverlayPositionChange.`);
+ .withContext(`Expected strategy to emit an instance of ConnectedOverlayPositionChange.`)
+ .toBe(true);
// If the strategy is re-applied and the initial position would now fit,
// the position change event should be emitted again.
@@ -1371,7 +1374,7 @@ describe('FlexibleConnectedPositionStrategy', () => {
let overlayRect = overlayRef.overlayElement.getBoundingClientRect();
expect(Math.floor(overlayRect.top))
- .toBe(0, 'Expected overlay to be in the viewport initially.');
+ .withContext('Expected overlay to be in the viewport initially.').toBe(0);
window.scroll(0, 100);
overlayRef.updatePosition();
@@ -1379,7 +1382,7 @@ describe('FlexibleConnectedPositionStrategy', () => {
overlayRect = overlayRef.overlayElement.getBoundingClientRect();
expect(Math.floor(overlayRect.top))
- .toBe(0, 'Expected overlay to stay in the viewport after scrolling.');
+ .withContext('Expected overlay to stay in the viewport after scrolling.').toBe(0);
window.scroll(0, 0);
document.body.removeChild(veryLargeElement);
@@ -1411,7 +1414,8 @@ describe('FlexibleConnectedPositionStrategy', () => {
const scrollBy = 100;
let initialOverlayTop = Math.floor(overlayRef.overlayElement.getBoundingClientRect().top);
- expect(initialOverlayTop).toBe(0, 'Expected overlay to be inside the viewport initially.');
+ expect(initialOverlayTop)
+ .withContext('Expected overlay to be inside the viewport initially.').toBe(0);
window.scroll(0, scrollBy);
overlayRef.updatePosition();
@@ -1419,10 +1423,12 @@ describe('FlexibleConnectedPositionStrategy', () => {
let currentOverlayTop = Math.floor(overlayRef.overlayElement.getBoundingClientRect().top);
- expect(currentOverlayTop).toBeLessThan(0,
- 'Expected overlay to no longer be completely inside the viewport.');
- expect(currentOverlayTop).toBe(initialOverlayTop - scrollBy,
- 'Expected overlay to maintain its previous position.');
+ expect(currentOverlayTop)
+ .withContext('Expected overlay to no longer be completely inside the viewport.')
+ .toBeLessThan(0);
+ expect(currentOverlayTop)
+ .withContext('Expected overlay to maintain its previous position.')
+ .toBe(initialOverlayTop - scrollBy);
window.scroll(0, 0);
document.body.removeChild(veryLargeElement);
diff --git a/src/cdk/overlay/scroll/block-scroll-strategy.spec.ts b/src/cdk/overlay/scroll/block-scroll-strategy.spec.ts
index 3fa45f4554b0..c6002501f46d 100644
--- a/src/cdk/overlay/scroll/block-scroll-strategy.spec.ts
+++ b/src/cdk/overlay/scroll/block-scroll-strategy.spec.ts
@@ -51,23 +51,24 @@ describe('BlockScrollStrategy', () => {
it('should toggle scroll blocking along the y axis', skipIOS(() => {
window.scroll(0, 100);
expect(viewport.getViewportScrollPosition().top)
- .toBe(100, 'Expected viewport to be scrollable initially.');
+ .withContext('Expected viewport to be scrollable initially.').toBe(100);
overlayRef.attach(componentPortal);
expect(documentElement.style.top)
- .toBe('-100px', 'Expected element to be offset by the previous scroll amount.');
+ .withContext('Expected element to be offset by the previous scroll amount.')
+ .toBe('-100px');
window.scroll(0, 300);
expect(viewport.getViewportScrollPosition().top)
- .toBe(100, 'Expected the viewport not to scroll.');
+ .withContext('Expected the viewport not to scroll.').toBe(100);
overlayRef.detach();
expect(viewport.getViewportScrollPosition().top)
- .toBe(100, 'Expected old scroll position to have bee restored after disabling.');
+ .withContext('Expected old scroll position to have bee restored after disabling.').toBe(100);
window.scroll(0, 300);
expect(viewport.getViewportScrollPosition().top)
- .toBe(300, 'Expected user to be able to scroll after disabling.');
+ .withContext('Expected user to be able to scroll after disabling.').toBe(300);
}));
@@ -77,23 +78,24 @@ describe('BlockScrollStrategy', () => {
window.scroll(100, 0);
expect(viewport.getViewportScrollPosition().left)
- .toBe(100, 'Expected viewport to be scrollable initially.');
+ .withContext('Expected viewport to be scrollable initially.').toBe(100);
overlayRef.attach(componentPortal);
expect(documentElement.style.left)
- .toBe('-100px', 'Expected element to be offset by the previous scroll amount.');
+ .withContext('Expected element to be offset by the previous scroll amount.')
+ .toBe('-100px');
window.scroll(300, 0);
expect(viewport.getViewportScrollPosition().left)
- .toBe(100, 'Expected the viewport not to scroll.');
+ .withContext('Expected the viewport not to scroll.').toBe(100);
overlayRef.detach();
expect(viewport.getViewportScrollPosition().left)
- .toBe(100, 'Expected old scroll position to have bee restored after disabling.');
+ .withContext('Expected old scroll position to have bee restored after disabling.').toBe(100);
window.scroll(300, 0);
expect(viewport.getViewportScrollPosition().left)
- .toBe(300, 'Expected user to be able to scroll after disabling.');
+ .withContext('Expected user to be able to scroll after disabling.').toBe(300);
}));
diff --git a/src/cdk/portal/portal.spec.ts b/src/cdk/portal/portal.spec.ts
index 0d14b13a1cba..16bc761a0e9e 100644
--- a/src/cdk/portal/portal.spec.ts
+++ b/src/cdk/portal/portal.spec.ts
@@ -88,11 +88,12 @@ describe('Portals', () => {
const domPortal = new DomPortal(testAppComponent.domPortalContent);
const initialParent = domPortal.element.parentNode!;
- expect(innerContent).toBeTruthy('Expected portal content to be rendered.');
+ expect(innerContent)
+ .withContext('Expected portal content to be rendered.').toBeTruthy();
expect(domPortal.element.contains(innerContent))
- .toBe(true, 'Expected content to be inside portal on init.');
+ .withContext('Expected content to be inside portal on init.').toBe(true);
expect(hostContainer.contains(innerContent))
- .toBe(false, 'Expected content to be outside of portal outlet.');
+ .withContext('Expected content to be outside of portal outlet.').toBe(false);
testAppComponent.selectedPortal = domPortal;
fixture.detectChanges();
@@ -100,16 +101,17 @@ describe('Portals', () => {
expect(domPortal.element.parentNode)
.not.toBe(initialParent, 'Expected portal to be out of the initial parent on attach.');
expect(hostContainer.contains(innerContent))
- .toBe(true, 'Expected content to be inside the outlet on attach.');
+ .withContext('Expected content to be inside the outlet on attach.').toBe(true);
expect(testAppComponent.portalOutlet.hasAttached()).toBe(true);
testAppComponent.selectedPortal = undefined;
fixture.detectChanges();
expect(domPortal.element.parentNode)
- .toBe(initialParent, 'Expected portal to be back inside initial parent on detach.');
+ .withContext('Expected portal to be back inside initial parent on detach.')
+ .toBe(initialParent);
expect(hostContainer.contains(innerContent))
- .toBe(false, 'Expected content to be removed from outlet on detach.');
+ .withContext('Expected content to be removed from outlet on detach.').toBe(false);
expect(testAppComponent.portalOutlet.hasAttached()).toBe(false);
});
@@ -550,25 +552,28 @@ describe('Portals', () => {
let componentInstance: PizzaMsg = portal.attach(host).instance;
expect(componentInstance instanceof PizzaMsg)
- .toBe(true, 'Expected a PizzaMsg component to be created');
+ .withContext('Expected a PizzaMsg component to be created').toBe(true);
expect(someDomElement.textContent)
- .toContain('Pizza', 'Expected the static string "Pizza" in the DomPortalOutlet.');
+ .withContext('Expected the static string "Pizza" in the DomPortalOutlet.')
+ .toContain('Pizza');
componentInstance.snack = new Chocolate();
someFixture.detectChanges();
expect(someDomElement.textContent)
- .toContain('Chocolate', 'Expected the bound string "Chocolate" in the DomPortalOutlet');
+ .withContext('Expected the bound string "Chocolate" in the DomPortalOutlet')
+ .toContain('Chocolate');
host.detach();
expect(someDomElement.innerHTML)
- .toBe('', 'Expected the DomPortalOutlet to be empty after detach');
+ .withContext('Expected the DomPortalOutlet to be empty after detach').toBe('');
});
it('should call the dispose function even if the host has no attached content', () => {
let spy = jasmine.createSpy('host dispose spy');
- expect(host.hasAttached()).toBe(false, 'Expected host not to have attached content.');
+ expect(host.hasAttached())
+ .withContext('Expected host not to have attached content.').toBe(false);
host.setDisposeFn(spy);
host.dispose();
diff --git a/src/cdk/schematics/ng-add/index.spec.ts b/src/cdk/schematics/ng-add/index.spec.ts
index e65f416b1dd1..3c4eb04c6ea9 100644
--- a/src/cdk/schematics/ng-add/index.spec.ts
+++ b/src/cdk/schematics/ng-add/index.spec.ts
@@ -24,11 +24,11 @@ describe('CDK ng-add', () => {
expect(dependencies['@angular/cdk']).toBe('~0.0.0-PLACEHOLDER');
expect(Object.keys(dependencies))
- .toEqual(
- Object.keys(dependencies).sort(),
- 'Expected the modified "dependencies" to be sorted alphabetically.');
- expect(runner.tasks.some(task => task.name === 'node-package')).toBe(true,
- 'Expected the package manager to be scheduled in order to update lock files.');
+ .withContext('Expected the modified "dependencies" to be sorted alphabetically.')
+ .toEqual(Object.keys(dependencies).sort());
+ expect(runner.tasks.some(task => task.name === 'node-package'))
+ .withContext('Expected the package manager to be scheduled in order to update lock files.')
+ .toBe(true);
});
it('should respect version range from CLI ng-add command', async () => {
@@ -41,7 +41,8 @@ describe('CDK ng-add', () => {
const dependencies = packageJson.dependencies;
expect(dependencies['@angular/cdk']).toBe('^9.0.0');
- expect(runner.tasks.some(task => task.name === 'node-package')).toBe(false,
- 'Expected the package manager to not run since the CDK version was already inserted.');
+ expect(runner.tasks.some(task => task.name === 'node-package'))
+ .withContext('Expected the package manager to not run since the CDK version ' +
+ 'was already inserted.').toBe(false);
});
});
diff --git a/src/cdk/schematics/ng-generate/drag-drop/index.spec.ts b/src/cdk/schematics/ng-generate/drag-drop/index.spec.ts
index 8f8c5f1363eb..f4716734710e 100644
--- a/src/cdk/schematics/ng-generate/drag-drop/index.spec.ts
+++ b/src/cdk/schematics/ng-generate/drag-drop/index.spec.ts
@@ -86,14 +86,14 @@ describe('CDK drag-drop schematic', () => {
// In this case we expect the schematic to generate a plain "css" file because
// the component schematics are using CSS style templates which are not compatible
// with all CLI supported styles (e.g. Stylus or Sass)
- expect(tree.files)
- .toContain(
- '/projects/material/src/app/foo/foo.component.css',
- 'Expected the schematic to generate a plain "css" file.');
- expect(tree.files)
- .not.toContain(
- '/projects/material/src/app/foo/foo.component.styl',
- 'Expected the schematic to not generate a "stylus" file');
+ // In this case we expect the schematic to generate a plain "css" file because
+ // the component schematics are using CSS style templates which are not compatible
+ // with all CLI supported styles (e.g. Stylus or Sass)
+ expect(tree.files).withContext('Expected the schematic to generate a plain "css" file.')
+ .toContain('/projects/material/src/app/foo/foo.component.css');
+ expect(tree.files).not
+ .withContext('Expected the schematic to not generate a "stylus" file')
+ .toContain('/projects/material/src/app/foo/foo.component.styl');
});
it('should fall back to the @schematics/angular:component option value', async () => {
diff --git a/src/cdk/schematics/ng-update/test-cases/misc/external-resource-resolution.spec.ts b/src/cdk/schematics/ng-update/test-cases/misc/external-resource-resolution.spec.ts
index e27a84bccef8..5971c58d2176 100644
--- a/src/cdk/schematics/ng-update/test-cases/misc/external-resource-resolution.spec.ts
+++ b/src/cdk/schematics/ng-update/test-cases/misc/external-resource-resolution.spec.ts
@@ -19,10 +19,10 @@ describe('ng-update external resource resolution', () => {
await runFixers();
expect(appTree.readContent('/projects/material/test.html'))
- .toBe(expected, 'Expected absolute devkit tree paths to work.');
+ .withContext('Expected absolute devkit tree paths to work.').toBe(expected);
expect(appTree.readContent('/projects/cdk-testing/src/some-tmpl.html'))
- .toBe(expected, 'Expected relative paths with parent segments to work.');
+ .withContext('Expected relative paths with parent segments to work.').toBe(expected);
expect(appTree.readContent('/projects/cdk-testing/src/test-cases/local.html'))
- .toBe(expected, 'Expected relative paths without explicit dot to work.');
+ .withContext('Expected relative paths without explicit dot to work.').toBe(expected);
});
});
diff --git a/src/cdk/scrolling/scroll-dispatcher.spec.ts b/src/cdk/scrolling/scroll-dispatcher.spec.ts
index 4f7c56db5f64..6fb01cdcfa03 100644
--- a/src/cdk/scrolling/scroll-dispatcher.spec.ts
+++ b/src/cdk/scrolling/scroll-dispatcher.spec.ts
@@ -217,7 +217,8 @@ describe('ScrollDispatcher', () => {
}));
it('should lazily add global listeners as service subscriptions are added and removed', () => {
- expect(scroll._globalSubscription).toBeNull('Expected no global listeners on init.');
+ expect(scroll._globalSubscription)
+ .withContext('Expected no global listeners on init.').toBeNull();
const subscription = scroll.scrolled(0).subscribe(() => {});
@@ -234,34 +235,41 @@ describe('ScrollDispatcher', () => {
const fixture = TestBed.createComponent(NestedScrollingComponent);
fixture.detectChanges();
- expect(scroll._globalSubscription).toBeNull('Expected no global listeners on init.');
- expect(scroll.scrollContainers.size).toBe(4, 'Expected multiple scrollables');
+ expect(scroll._globalSubscription)
+ .withContext('Expected no global listeners on init.')
+ .toBeNull();
+ expect(scroll.scrollContainers.size).withContext('Expected multiple scrollables').toBe(4);
const subscription = scroll.scrolled(0).subscribe(() => {});
- expect(scroll._globalSubscription).toBeTruthy(
- 'Expected global listeners after a subscription has been added.');
+ expect(scroll._globalSubscription)
+ .withContext('Expected global listeners after a subscription has been added.')
+ .toBeTruthy();
subscription.unsubscribe();
- expect(scroll._globalSubscription).toBeNull(
- 'Expected global listeners to have been removed after the subscription has stopped.');
+ expect(scroll._globalSubscription)
+ .withContext('Expected global listeners to have been removed after ' +
+ 'the subscription has stopped.').toBeNull();
expect(scroll.scrollContainers.size)
- .toBe(4, 'Expected scrollable count to stay the same');
+ .withContext('Expected scrollable count to stay the same').toBe(4);
});
it('should remove the global subscription on destroy', () => {
- expect(scroll._globalSubscription).toBeNull('Expected no global listeners on init.');
+ expect(scroll._globalSubscription)
+ .withContext('Expected no global listeners on init.').toBeNull();
const subscription = scroll.scrolled(0).subscribe(() => {});
- expect(scroll._globalSubscription).toBeTruthy(
- 'Expected global listeners after a subscription has been added.');
+ expect(scroll._globalSubscription)
+ .withContext('Expected global listeners after a subscription has been added.')
+ .toBeTruthy();
scroll.ngOnDestroy();
- expect(scroll._globalSubscription).toBeNull(
- 'Expected global listeners to have been removed after the subscription has stopped.');
+ expect(scroll._globalSubscription)
+ .withContext('Expected global listeners to have been removed after ' +
+ 'the subscription has stopped.').toBeNull();
subscription.unsubscribe();
});
diff --git a/src/cdk/scrolling/scrollable.spec.ts b/src/cdk/scrolling/scrollable.spec.ts
index c9c3d1a06931..141b468b7c21 100644
--- a/src/cdk/scrolling/scrollable.spec.ts
+++ b/src/cdk/scrolling/scrollable.spec.ts
@@ -10,10 +10,12 @@ function expectOverlapping(el1: ElementRef, el2: ElementRef, e
r1.left < r2.right && r1.right > r2.left && r1.top < r2.bottom && r1.bottom > r2.top;
if (expected) {
expect(actual)
- .toBe(expected, `${JSON.stringify(r1)} should overlap with ${JSON.stringify(r2)}`);
+ .withContext(`${JSON.stringify(r1)} should overlap with ${JSON.stringify(r2)}`)
+ .toBe(expected);
} else {
expect(actual)
- .toBe(expected, `${JSON.stringify(r1)} should not overlap with ${JSON.stringify(r2)}`);
+ .withContext(`${JSON.stringify(r1)} should not overlap with ${JSON.stringify(r2)}`)
+ .toBe(expected);
}
}
diff --git a/src/cdk/scrolling/virtual-scroll-viewport.spec.ts b/src/cdk/scrolling/virtual-scroll-viewport.spec.ts
index 7a6695eac248..fe5d1b27f2d1 100644
--- a/src/cdk/scrolling/virtual-scroll-viewport.spec.ts
+++ b/src/cdk/scrolling/virtual-scroll-viewport.spec.ts
@@ -53,7 +53,7 @@ describe('CdkVirtualScrollViewport', () => {
const contentWrapper =
viewport.elementRef.nativeElement.querySelector('.cdk-virtual-scroll-content-wrapper')!;
expect(contentWrapper.children.length)
- .toBe(4, 'should render 4 50px items to fill 200px space');
+ .withContext('should render 4 50px items to fill 200px space').toBe(4);
}));
it('should get the data length', fakeAsync(() => {
@@ -97,7 +97,8 @@ describe('CdkVirtualScrollViewport', () => {
finishInit(fixture);
expect(viewport.getRenderedRange())
- .toEqual({start: 0, end: 4}, 'should render the first 4 50px items to fill 200px space');
+ .withContext('should render the first 4 50px items to fill 200px space')
+ .toEqual({ start: 0, end: 4 });
}));
it('should get the rendered content offset', fakeAsync(() => {
@@ -106,8 +107,9 @@ describe('CdkVirtualScrollViewport', () => {
fixture.detectChanges();
flush();
- expect(viewport.getOffsetToRenderedContentStart()).toBe(testComponent.itemSize,
- 'should have 50px offset since first 50px item is not rendered');
+ expect(viewport.getOffsetToRenderedContentStart())
+ .withContext('should have 50px offset since first 50px item is not rendered')
+ .toBe(testComponent.itemSize);
}));
it('should get the scroll offset', fakeAsync(() => {
@@ -123,23 +125,25 @@ describe('CdkVirtualScrollViewport', () => {
finishInit(fixture);
expect(viewport.measureRenderedContentSize())
- .toBe(testComponent.viewportSize,
- 'should render 4 50px items with combined size of 200px to fill 200px space');
+ .withContext('should render 4 50px items with combined size of 200px to fill 200px space')
+ .toBe(testComponent.viewportSize);
}));
it('should measure range size', fakeAsync(() => {
finishInit(fixture);
- expect(viewport.measureRangeSize({start: 1, end: 3}))
- .toBe(testComponent.itemSize * 2, 'combined size of 2 50px items should be 100px');
+ expect(viewport.measureRangeSize({ start: 1, end: 3 }))
+ .withContext('combined size of 2 50px items should be 100px')
+ .toBe(testComponent.itemSize * 2);
}));
it('should measure range size when items has a margin', fakeAsync(() => {
fixture.componentInstance.hasMargin = true;
finishInit(fixture);
- expect(viewport.measureRangeSize({start: 1, end: 3})).toBe(testComponent.itemSize * 2 + 10,
- 'combined size of 2 50px items with a 10px margin should be 110px');
+ expect(viewport.measureRangeSize({ start: 1, end: 3 }))
+ .withContext('combined size of 2 50px items with a 10px margin should be 110px')
+ .toBe(testComponent.itemSize * 2 + 10);
}));
it('should set total content size', fakeAsync(() => {
@@ -192,8 +196,10 @@ describe('CdkVirtualScrollViewport', () => {
flush();
const items = fixture.elementRef.nativeElement.querySelectorAll('.item');
- expect(items.length).toBe(1, 'Expected 1 item to be rendered');
- expect(items[0].innerText.trim()).toBe('2 - 2', 'Expected item with index 2 to be rendered');
+ expect(items.length)
+ .withContext('Expected 1 item to be rendered').toBe(1);
+ expect(items[0].innerText.trim())
+ .withContext('Expected item with index 2 to be rendered').toBe('2 - 2');
}));
it('should set content offset to top of content', fakeAsync(() => {
@@ -298,14 +304,15 @@ describe('CdkVirtualScrollViewport', () => {
end: Math.ceil((offset + testComponent.viewportSize) / testComponent.itemSize)
};
expect(viewport.getRenderedRange())
- .toEqual(expectedRange,
- `rendered range should match expected value at scroll offset ${offset}`);
+ .withContext(`rendered range should match expected value at scroll offset ${offset}`)
+ .toEqual(expectedRange);
expect(viewport.getOffsetToRenderedContentStart())
- .toBe(expectedRange.start * testComponent.itemSize,
- `rendered content offset should match expected value at scroll offset ${offset}`);
+ .withContext(`rendered content offset should match expected value at ` +
+ `scroll offset ${offset}`)
+ .toBe(expectedRange.start * testComponent.itemSize);
expect(viewport.measureRenderedContentSize())
- .toBe((expectedRange.end - expectedRange.start) * testComponent.itemSize,
- `rendered content size should match expected value at offset ${offset}`);
+ .withContext(`rendered content size should match expected value at offset ${offset}`)
+ .toBe((expectedRange.end - expectedRange.start) * testComponent.itemSize);
}
}));
@@ -324,14 +331,14 @@ describe('CdkVirtualScrollViewport', () => {
end: Math.ceil((offset + testComponent.viewportSize) / testComponent.itemSize)
};
expect(viewport.getRenderedRange())
- .toEqual(expectedRange,
- `rendered range should match expected value at scroll offset ${offset}`);
+ .withContext(`rendered range should match expected value at scroll offset ${offset}`)
+ .toEqual(expectedRange);
expect(viewport.getOffsetToRenderedContentStart())
- .toBe(expectedRange.start * testComponent.itemSize,
- `rendered content offset should match expected value at scroll offset ${offset}`);
+ .withContext(`rendered content offset should match expected value at scroll ` +
+ `offset ${offset}`).toBe(expectedRange.start * testComponent.itemSize);
expect(viewport.measureRenderedContentSize())
- .toBe((expectedRange.end - expectedRange.start) * testComponent.itemSize,
- `rendered content size should match expected value at offset ${offset}`);
+ .withContext(`rendered content size should match expected value at offset ${offset}`)
+ .toBe((expectedRange.end - expectedRange.start) * testComponent.itemSize);
}
}));
@@ -340,9 +347,9 @@ describe('CdkVirtualScrollViewport', () => {
testComponent.maxBufferPx = testComponent.itemSize;
finishInit(fixture);
- expect(viewport.getRenderedRange()).toEqual({start: 0, end: 5},
- 'should render the first 5 50px items to fill 200px space, plus one buffer element at' +
- ' the end');
+ expect(viewport.getRenderedRange())
+ .withContext('should render the first 5 50px items to fill 200px space, ' +
+ 'plus one buffer element at the end').toEqual({ start: 0, end: 5 });
}));
it('should render buffer element at the start and end when scrolled to the middle',
@@ -354,9 +361,9 @@ describe('CdkVirtualScrollViewport', () => {
fixture.detectChanges();
flush();
- expect(viewport.getRenderedRange()).toEqual({start: 1, end: 7},
- 'should render 6 50px items to fill 200px space, plus one buffer element at the' +
- ' start and end');
+ expect(viewport.getRenderedRange())
+ .withContext('should render 6 50px items to fill 200px space, plus one ' +
+ 'buffer element at the start and end').toEqual({ start: 1, end: 7 });
}));
it('should render buffer element at the start when scrolled to the bottom', fakeAsync(() => {
@@ -367,9 +374,9 @@ describe('CdkVirtualScrollViewport', () => {
fixture.detectChanges();
flush();
- expect(viewport.getRenderedRange()).toEqual({start: 5, end: 10},
- 'should render the last 5 50px items to fill 200px space, plus one buffer element at' +
- ' the start');
+ expect(viewport.getRenderedRange())
+ .withContext('should render the last 5 50px items to fill 200px space, plus one ' +
+ 'buffer element at the start').toEqual({ start: 5, end: 10 });
}));
it('should handle dynamic item size', fakeAsync(() => {
@@ -379,14 +386,16 @@ describe('CdkVirtualScrollViewport', () => {
flush();
expect(viewport.getRenderedRange())
- .toEqual({start: 2, end: 6}, 'should render 4 50px items to fill 200px space');
+ .withContext('should render 4 50px items to fill 200px space')
+ .toEqual({ start: 2, end: 6 });
testComponent.itemSize *= 2;
fixture.detectChanges();
flush();
expect(viewport.getRenderedRange())
- .toEqual({start: 1, end: 3}, 'should render 2 100px items to fill 200px space');
+ .withContext('should render 2 100px items to fill 200px space')
+ .toEqual({ start: 1, end: 3 });
}));
it('should handle dynamic buffer size', fakeAsync(() => {
@@ -396,7 +405,8 @@ describe('CdkVirtualScrollViewport', () => {
flush();
expect(viewport.getRenderedRange())
- .toEqual({start: 2, end: 6}, 'should render 4 50px items to fill 200px space');
+ .withContext('should render 4 50px items to fill 200px space')
+ .toEqual({ start: 2, end: 6 });
testComponent.minBufferPx = testComponent.itemSize;
testComponent.maxBufferPx = testComponent.itemSize;
@@ -404,7 +414,8 @@ describe('CdkVirtualScrollViewport', () => {
flush();
expect(viewport.getRenderedRange())
- .toEqual({start: 1, end: 7}, 'should expand to 1 buffer element on each side');
+ .withContext('should expand to 1 buffer element on each side')
+ .toEqual({ start: 1, end: 7 });
}));
it('should handle dynamic item array', fakeAsync(() => {
@@ -414,14 +425,15 @@ describe('CdkVirtualScrollViewport', () => {
flush();
expect(viewport.getOffsetToRenderedContentStart())
- .toBe(testComponent.itemSize * 6, 'should be scrolled to bottom of 10 item list');
+ .withContext('should be scrolled to bottom of 10 item list')
+ .toBe(testComponent.itemSize * 6);
testComponent.items = Array(5).fill(0);
fixture.detectChanges();
flush();
expect(viewport.getOffsetToRenderedContentStart())
- .toBe(testComponent.itemSize, 'should be scrolled to bottom of 5 item list');
+ .withContext('should be scrolled to bottom of 5 item list').toBe(testComponent.itemSize);
}));
it('should handle dynamic item array with dynamic buffer', fakeAsync(() => {
@@ -431,7 +443,8 @@ describe('CdkVirtualScrollViewport', () => {
flush();
expect(viewport.getOffsetToRenderedContentStart())
- .toBe(testComponent.itemSize * 6, 'should be scrolled to bottom of 10 item list');
+ .withContext('should be scrolled to bottom of 10 item list')
+ .toBe(testComponent.itemSize * 6);
testComponent.items = Array(5).fill(0);
testComponent.minBufferPx = testComponent.itemSize;
@@ -441,7 +454,7 @@ describe('CdkVirtualScrollViewport', () => {
flush();
expect(viewport.getOffsetToRenderedContentStart())
- .toBe(0, 'should render from first item');
+ .withContext('should render from first item').toBe(0);
}));
it('should handle dynamic item array keeping position when possible', fakeAsync(() => {
@@ -452,14 +465,14 @@ describe('CdkVirtualScrollViewport', () => {
flush();
expect(viewport.getOffsetToRenderedContentStart())
- .toBe(testComponent.itemSize * 50, 'should be scrolled to index 50 item list');
+ .withContext('should be scrolled to index 50 item list').toBe(testComponent.itemSize * 50);
testComponent.items = Array(54).fill(0);
fixture.detectChanges();
flush();
expect(viewport.getOffsetToRenderedContentStart())
- .toBe(testComponent.itemSize * 50, 'should be kept the scroll position');
+ .withContext('should be kept the scroll position').toBe(testComponent.itemSize * 50);
}));
it('should update viewport as user scrolls right in horizontal mode', fakeAsync(() => {
@@ -478,14 +491,14 @@ describe('CdkVirtualScrollViewport', () => {
end: Math.ceil((offset + testComponent.viewportSize) / testComponent.itemSize)
};
expect(viewport.getRenderedRange())
- .toEqual(expectedRange,
- `rendered range should match expected value at scroll offset ${offset}`);
+ .withContext(`rendered range should match expected value at scroll offset ${offset}`)
+ .toEqual(expectedRange);
expect(viewport.getOffsetToRenderedContentStart())
- .toBe(expectedRange.start * testComponent.itemSize,
- `rendered content offset should match expected value at scroll offset ${offset}`);
+ .withContext(`rendered content offset should match expected value at scroll ` +
+ `offset ${offset}`).toBe(expectedRange.start * testComponent.itemSize);
expect(viewport.measureRenderedContentSize())
- .toBe((expectedRange.end - expectedRange.start) * testComponent.itemSize,
- `rendered content size should match expected value at offset ${offset}`);
+ .withContext(`rendered content size should match expected value at offset ${offset}`)
+ .toBe((expectedRange.end - expectedRange.start) * testComponent.itemSize);
}
}));
@@ -505,14 +518,14 @@ describe('CdkVirtualScrollViewport', () => {
end: Math.ceil((offset + testComponent.viewportSize) / testComponent.itemSize)
};
expect(viewport.getRenderedRange())
- .toEqual(expectedRange,
- `rendered range should match expected value at scroll offset ${offset}`);
+ .withContext(`rendered range should match expected value at scroll offset ${offset}`)
+ .toEqual(expectedRange);
expect(viewport.getOffsetToRenderedContentStart())
- .toBe(expectedRange.start * testComponent.itemSize,
- `rendered content offset should match expected value at scroll offset ${offset}`);
+ .withContext(`rendered content offset should match expected value at scroll ` +
+ `offset ${offset}`).toBe(expectedRange.start * testComponent.itemSize);
expect(viewport.measureRenderedContentSize())
- .toBe((expectedRange.end - expectedRange.start) * testComponent.itemSize,
- `rendered content size should match expected value at offset ${offset}`);
+ .withContext(`rendered content size should match expected value at offset ${offset}`)
+ .toBe((expectedRange.end - expectedRange.start) * testComponent.itemSize);
}
}));
@@ -522,7 +535,7 @@ describe('CdkVirtualScrollViewport', () => {
finishInit(fixture);
expect(viewport.getRenderedRange())
- .toEqual({start: 0, end: 4}, 'newly emitted items should be rendered');
+ .withContext('newly emitted items should be rendered').toEqual({ start: 0, end: 4 });
}));
it('should work with an Observable', fakeAsync(() => {
@@ -531,14 +544,14 @@ describe('CdkVirtualScrollViewport', () => {
finishInit(fixture);
expect(viewport.getRenderedRange())
- .toEqual({start: 0, end: 0}, 'no items should be rendered');
+ .withContext('no items should be rendered').toEqual({ start: 0, end: 0 });
data.next([1, 2, 3]);
fixture.detectChanges();
flush();
expect(viewport.getRenderedRange())
- .toEqual({start: 0, end: 3}, 'newly emitted items should be rendered');
+ .withContext('newly emitted items should be rendered').toEqual({ start: 0, end: 3 });
}));
it('should work with a DataSource', fakeAsync(() => {
@@ -547,14 +560,14 @@ describe('CdkVirtualScrollViewport', () => {
finishInit(fixture);
expect(viewport.getRenderedRange())
- .toEqual({start: 0, end: 0}, 'no items should be rendered');
+ .withContext('no items should be rendered').toEqual({ start: 0, end: 0 });
data.next([1, 2, 3]);
fixture.detectChanges();
flush();
expect(viewport.getRenderedRange())
- .toEqual({start: 0, end: 3}, 'newly emitted items should be rendered');
+ .withContext('newly emitted items should be rendered').toEqual({ start: 0, end: 3 });
}));
it('should disconnect from data source on destroy', fakeAsync(() => {
@@ -692,21 +705,21 @@ describe('CdkVirtualScrollViewport', () => {
finishInit(fixture);
expect(viewport.getRenderedRange())
- .toEqual({start: 0, end: 6}, 'should have 2 buffer items initially');
+ .withContext('should have 2 buffer items initially').toEqual({ start: 0, end: 6 });
triggerScroll(viewport, 50);
fixture.detectChanges();
flush();
expect(viewport.getRenderedRange())
- .toEqual({start: 0, end: 6}, 'should not render additional buffer yet');
+ .withContext('should not render additional buffer yet').toEqual({ start: 0, end: 6 });
triggerScroll(viewport, 51);
fixture.detectChanges();
flush();
expect(viewport.getRenderedRange())
- .toEqual({start: 0, end: 8}, 'should render 2 more buffer items');
+ .withContext('should render 2 more buffer items').toEqual({ start: 0, end: 8 });
}));
it('should throw if maxBufferPx is less than minBufferPx', fakeAsync(() => {
diff --git a/src/cdk/table/table.spec.ts b/src/cdk/table/table.spec.ts
index d73dd322a50c..791b25bdd187 100644
--- a/src/cdk/table/table.spec.ts
+++ b/src/cdk/table/table.spec.ts
@@ -581,10 +581,11 @@ describe('CdkTable', () => {
thisFixture.detectChanges();
const rowGroups = Array.from(thisTableElement.querySelectorAll('thead, tbody, tfoot'));
- expect(rowGroups.length).toBe(3, 'Expected table to have a thead, tbody, and tfoot');
+ expect(rowGroups.length)
+ .withContext('Expected table to have a thead, tbody, and tfoot').toBe(3);
for (const group of rowGroups) {
expect(group.getAttribute('role'))
- .toBe('rowgroup', 'Expected thead, tbody, and tfoot to have role="rowgroup"');
+ .withContext('Expected thead, tbody, and tfoot to have role="rowgroup"').toBe('rowgroup');
}
});
@@ -594,9 +595,11 @@ describe('CdkTable', () => {
thisFixture.detectChanges();
const rowGroups: HTMLElement[] = Array.from(thisTableElement.querySelectorAll('thead, tfoot'));
- expect(rowGroups.length).toBe(2, 'Expected table to have a thead and tfoot');
+ expect(rowGroups.length)
+ .withContext('Expected table to have a thead and tfoot').toBe(2);
for (const group of rowGroups) {
- expect(group.style.display).toBe('none', 'Expected thead and tfoot to be `display: none`');
+ expect(group.style.display)
+ .withContext('Expected thead and tfoot to be `display: none`').toBe('none');
}
});
@@ -873,21 +876,25 @@ describe('CdkTable', () => {
expect(element.style.position).toBe('');
expect(element.style.zIndex || '0').toBe('0');
['top', 'bottom', 'left', 'right'].forEach(d => {
- expect(element.style[d] || 'unset').toBe('unset', `Expected ${d} to be unset`);
+ expect(element.style[d] || 'unset')
+ .withContext(`Expected ${d} to be unset`).toBe('unset');
});
});
}
function expectStickyStyles(element: any, zIndex: string, directions: PositionDirections = {}) {
expect(element.style.position).toContain('sticky');
- expect(element.style.zIndex).toBe(zIndex, `Expected zIndex to be ${zIndex}`);
+ expect(element.style.zIndex)
+ .withContext(`Expected zIndex to be ${zIndex}`).toBe(zIndex);
['top', 'bottom', 'left', 'right'].forEach(d => {
const directionValue = directions[d];
if (!directionValue) {
// If no expected position for this direction, must either be unset or empty string
- expect(element.style[d] || 'unset').toBe('unset', `Expected ${d} to be unset`);
+ // If no expected position for this direction, must either be unset or empty string
+ expect(element.style[d] || 'unset')
+ .withContext(`Expected ${d} to be unset`).toBe('unset');
return;
}
@@ -897,9 +904,10 @@ describe('CdkTable', () => {
// caused by individual browsers.
if (directionValue.includes('px')) {
expect(Math.round(parseInt(element.style[d])))
- .toBe(Math.round(parseInt(directionValue)), expectationMessage);
+ .withContext(expectationMessage).toBe(Math.round(parseInt(directionValue)));
} else {
- expect(element.style[d]).toBe(directionValue, expectationMessage);
+ expect(element.style[d])
+ .withContext(expectationMessage).toBe(directionValue);
}
});
}
diff --git a/src/cdk/text-field/autosize.spec.ts b/src/cdk/text-field/autosize.spec.ts
index 14c4ed412dad..bece03583a5e 100644
--- a/src/cdk/text-field/autosize.spec.ts
+++ b/src/cdk/text-field/autosize.spec.ts
@@ -63,9 +63,11 @@ describe('CdkTextareaAutosize', () => {
autosize.resizeToFitContent();
expect(textarea.clientHeight)
- .toBeGreaterThan(previousHeight, 'Expected textarea to have grown with added content.');
+ .withContext('Expected textarea to have grown with added content.')
+ .toBeGreaterThan(previousHeight);
expect(textarea.clientHeight)
- .toBe(textarea.scrollHeight, 'Expected textarea height to match its scrollHeight');
+ .withContext('Expected textarea height to match its scrollHeight')
+ .toBe(textarea.scrollHeight);
previousHeight = textarea.clientHeight;
textarea.value += `
@@ -80,9 +82,11 @@ describe('CdkTextareaAutosize', () => {
autosize.resizeToFitContent();
expect(textarea.clientHeight)
- .toBeGreaterThan(previousHeight, 'Expected textarea to have grown with added content.');
+ .withContext('Expected textarea to have grown with added content.')
+ .toBeGreaterThan(previousHeight);
expect(textarea.clientHeight)
- .toBe(textarea.scrollHeight, 'Expected textarea height to match its scrollHeight');
+ .withContext('Expected textarea height to match its scrollHeight')
+ .toBe(textarea.scrollHeight);
});
it('should keep the placeholder size if the value is shorter than the placeholder', () => {
@@ -103,7 +107,8 @@ describe('CdkTextareaAutosize', () => {
fixture.detectChanges();
expect(textarea.clientHeight)
- .toBe(textarea.scrollHeight, 'Expected textarea height to match its scrollHeight');
+ .withContext('Expected textarea height to match its scrollHeight')
+ .toBe(textarea.scrollHeight);
let previousHeight = textarea.clientHeight;
@@ -114,7 +119,7 @@ describe('CdkTextareaAutosize', () => {
autosize.resizeToFitContent();
expect(textarea.clientHeight)
- .toBe(previousHeight, 'Expected textarea height not to have changed');
+ .withContext('Expected textarea height not to have changed').toBe(previousHeight);
});
it('should set a min-height based on minRows', () => {
@@ -123,14 +128,16 @@ describe('CdkTextareaAutosize', () => {
fixture.componentInstance.minRows = 4;
fixture.detectChanges();
- expect(textarea.style.minHeight).toBeDefined('Expected a min-height to be set via minRows.');
+ expect(textarea.style.minHeight)
+ .withContext('Expected a min-height to be set via minRows.').toBeDefined();
let previousMinHeight = parseInt(textarea.style.minHeight as string);
fixture.componentInstance.minRows = 6;
fixture.detectChanges();
expect(parseInt(textarea.style.minHeight as string))
- .toBeGreaterThan(previousMinHeight, 'Expected increased min-height with minRows increase.');
+ .withContext('Expected increased min-height with minRows increase.')
+ .toBeGreaterThan(previousMinHeight);
});
it('should set a max-height based on maxRows', () => {
@@ -139,14 +146,16 @@ describe('CdkTextareaAutosize', () => {
fixture.componentInstance.maxRows = 4;
fixture.detectChanges();
- expect(textarea.style.maxHeight).toBeDefined('Expected a max-height to be set via maxRows.');
+ expect(textarea.style.maxHeight)
+ .withContext('Expected a max-height to be set via maxRows.').toBeDefined();
let previousMaxHeight = parseInt(textarea.style.maxHeight as string);
fixture.componentInstance.maxRows = 6;
fixture.detectChanges();
expect(parseInt(textarea.style.maxHeight as string))
- .toBeGreaterThan(previousMaxHeight, 'Expected increased max-height with maxRows increase.');
+ .withContext('Expected increased max-height with maxRows increase.')
+ .toBeGreaterThan(previousMaxHeight);
});
it('should reduce textarea height when minHeight decreases', () => {
@@ -155,14 +164,15 @@ describe('CdkTextareaAutosize', () => {
fixture.componentInstance.minRows = 6;
fixture.detectChanges();
- expect(textarea.style.minHeight).toBeDefined('Expected a min-height to be set via minRows.');
+ expect(textarea.style.minHeight)
+ .withContext('Expected a min-height to be set via minRows.').toBeDefined();
let previousHeight = parseInt(textarea.style.height!);
fixture.componentInstance.minRows = 3;
fixture.detectChanges();
expect(parseInt(textarea.style.height!))
- .toBeLessThan(previousHeight, 'Expected decreased height with minRows decrease.');
+ .withContext('Expected decreased height with minRows decrease.').toBeLessThan(previousHeight);
});
it('should export the cdkAutosize reference', () => {
@@ -172,24 +182,25 @@ describe('CdkTextareaAutosize', () => {
it('should initially set the rows of a textarea to one', () => {
expect(textarea.rows)
- .toBe(1, 'Expected the directive to initially set the rows property to one.');
+ .withContext('Expected the directive to initially set the rows property to one.').toBe(1);
fixture.componentInstance.minRows = 1;
fixture.detectChanges();
expect(textarea.rows)
- .toBe(1, 'Expected the textarea to have the rows property set to one.');
+ .withContext('Expected the textarea to have the rows property set to one.').toBe(1);
const previousMinHeight = parseInt(textarea.style.minHeight as string);
fixture.componentInstance.minRows = 2;
fixture.detectChanges();
- expect(textarea.rows).toBe(1, 'Expected the rows property to be set to one. ' +
- 'The amount of rows will be specified using CSS.');
+ expect(textarea.rows)
+ .withContext('Expected the rows property to be set to one. ' +
+ 'The amount of rows will be specified using CSS.').toBe(1);
expect(parseInt(textarea.style.minHeight as string))
- .toBeGreaterThan(previousMinHeight, 'Expected the textarea to grow to two rows.');
+ .withContext('Expected the textarea to grow to two rows.').toBeGreaterThan(previousMinHeight);
});
it('should calculate the proper height based on the specified amount of max rows', () => {
@@ -198,13 +209,15 @@ describe('CdkTextareaAutosize', () => {
autosize.resizeToFitContent();
expect(textarea.clientHeight)
- .toBe(textarea.scrollHeight, 'Expected textarea to not have a vertical scrollbar.');
+ .withContext('Expected textarea to not have a vertical scrollbar.')
+ .toBe(textarea.scrollHeight);
fixture.componentInstance.maxRows = 5;
fixture.detectChanges();
expect(textarea.clientHeight)
- .toBeLessThan(textarea.scrollHeight, 'Expected textarea to have a vertical scrollbar.');
+ .withContext('Expected textarea to have a vertical scrollbar.')
+ .toBeLessThan(textarea.scrollHeight);
});
it('should properly resize to content on init', () => {
@@ -225,7 +238,8 @@ describe('CdkTextareaAutosize', () => {
fixture.detectChanges();
expect(textarea.clientHeight)
- .toBe(textarea.scrollHeight, 'Expected textarea height to match its scrollHeight');
+ .withContext('Expected textarea height to match its scrollHeight')
+ .toBe(textarea.scrollHeight);
});
it('should properly resize to placeholder on init', () => {
@@ -246,7 +260,8 @@ describe('CdkTextareaAutosize', () => {
fixture.detectChanges();
expect(textarea.clientHeight)
- .toBe(textarea.scrollHeight, 'Expected textarea height to match its scrollHeight');
+ .withContext('Expected textarea height to match its scrollHeight')
+ .toBe(textarea.scrollHeight);
});
it('should resize when an associated form control value changes', fakeAsync(() => {
@@ -268,7 +283,8 @@ describe('CdkTextareaAutosize', () => {
fixtureWithForms.detectChanges();
expect(textarea.clientHeight)
- .toBeGreaterThan(previousHeight, 'Expected increased height when ngModel is updated.');
+ .withContext('Expected increased height when ngModel is updated.')
+ .toBeGreaterThan(previousHeight);
}));
it('should resize when the textarea value is changed programmatically', fakeAsync(() => {
@@ -284,7 +300,8 @@ describe('CdkTextareaAutosize', () => {
fixture.detectChanges();
expect(textarea.clientHeight)
- .toBeGreaterThan(previousHeight, 'Expected the textarea height to have increased.');
+ .withContext('Expected the textarea height to have increased.')
+ .toBeGreaterThan(previousHeight);
}));
it('should trigger a resize when the window is resized', fakeAsync(() => {
@@ -317,26 +334,26 @@ describe('CdkTextareaAutosize', () => {
fixtureWithoutAutosize.detectChanges();
expect(textarea.clientHeight)
- .toEqual(previousHeight, 'Expected textarea to still have the same size.');
+ .withContext('Expected textarea to still have the same size.').toEqual(previousHeight);
expect(textarea.clientHeight)
- .toBeLessThan(textarea.scrollHeight, 'Expected textarea to a have scrollbar.');
+ .withContext('Expected textarea to a have scrollbar.').toBeLessThan(textarea.scrollHeight);
autosize.enabled = true;
fixtureWithoutAutosize.detectChanges();
expect(textarea.clientHeight)
- .toBeGreaterThan(previousHeight,
- 'Expected textarea to have grown after enabling autosize.');
+ .withContext('Expected textarea to have grown after enabling autosize.')
+ .toBeGreaterThan(previousHeight);
expect(textarea.clientHeight)
- .toBe(textarea.scrollHeight, 'Expected textarea not to have a scrollbar');
+ .withContext('Expected textarea not to have a scrollbar').toBe(textarea.scrollHeight);
autosize.enabled = false;
fixtureWithoutAutosize.detectChanges();
expect(textarea.clientHeight)
- .toEqual(previousHeight, 'Expected textarea to have the original size.');
+ .withContext('Expected textarea to have the original size.').toEqual(previousHeight);
expect(textarea.clientHeight)
- .toBeLessThan(textarea.scrollHeight, 'Expected textarea to have a scrollbar.');
+ .withContext('Expected textarea to have a scrollbar.').toBeLessThan(textarea.scrollHeight);
}));
});
diff --git a/src/cdk/tree/control/flat-tree-control.spec.ts b/src/cdk/tree/control/flat-tree-control.spec.ts
index 0458d03bf33f..bedf0a92be8a 100644
--- a/src/cdk/tree/control/flat-tree-control.spec.ts
+++ b/src/cdk/tree/control/flat-tree-control.spec.ts
@@ -21,34 +21,39 @@ describe('CdkFlatTreeControl', () => {
expect(treeControl.isExpanded(secondNode))
- .toBeTruthy('Expect second node to be expanded');
+ .withContext('Expect second node to be expanded')
+ .toBeTruthy();
expect(treeControl.expansionModel.selected)
- .toContain(secondNode, 'Expect second node in expansionModel');
+ .withContext('Expect second node in expansionModel').toContain(secondNode);
expect(treeControl.expansionModel.selected.length)
- .toBe(1, 'Expect only second node in expansionModel');
+ .withContext('Expect only second node in expansionModel').toBe(1);
treeControl.toggle(sixthNode);
expect(treeControl.isExpanded(secondNode))
- .toBeTruthy('Expect second node to stay expanded');
+ .withContext('Expect second node to stay expanded')
+ .toBeTruthy();
expect(treeControl.isExpanded(sixthNode))
- .toBeTruthy('Expect sixth node to be expanded');
+ .withContext('Expect sixth node to be expanded')
+ .toBeTruthy();
expect(treeControl.expansionModel.selected)
- .toContain(sixthNode, 'Expect sixth node in expansionModel');
+ .withContext('Expect sixth node in expansionModel').toContain(sixthNode);
expect(treeControl.expansionModel.selected)
- .toContain(secondNode, 'Expect second node in expansionModel');
+ .withContext('Expect second node in expansionModel').toContain(secondNode);
expect(treeControl.expansionModel.selected.length)
- .toBe(2, 'Expect two dataNodes in expansionModel');
+ .withContext('Expect two dataNodes in expansionModel').toBe(2);
treeControl.collapse(secondNode);
expect(treeControl.isExpanded(secondNode))
- .toBeFalsy('Expect second node to be collapsed');
+ .withContext('Expect second node to be collapsed')
+ .toBeFalsy();
expect(treeControl.expansionModel.selected.length)
- .toBe(1, 'Expect one node in expansionModel');
- expect(treeControl.isExpanded(sixthNode)).toBeTruthy('Expect sixth node to stay expanded');
+ .withContext('Expect one node in expansionModel').toBe(1);
+ expect(treeControl.isExpanded(sixthNode))
+ .withContext('Expect sixth node to stay expanded').toBeTruthy();
expect(treeControl.expansionModel.selected)
- .toContain(sixthNode, 'Expect sixth node in expansionModel');
+ .withContext('Expect sixth node in expansionModel').toContain(sixthNode);
});
it('should return correct expandable values', () => {
@@ -57,11 +62,13 @@ describe('CdkFlatTreeControl', () => {
for (let i = 0; i < 10; i++) {
expect(treeControl.isExpandable(nodes[i]))
- .toBeTruthy(`Expect node[${i}] to be expandable`);
+ .withContext(`Expect node[${i}] to be expandable`)
+ .toBeTruthy();
for (let j = 0; j < 4; j++) {
expect(treeControl.isExpandable(nodes[i].children[j]))
- .toBeFalsy(`Expect node[${i}]'s child[${j}] to be not expandable`);
+ .withContext(`Expect node[${i}]'s child[${j}] to be not expandable`)
+ .toBeFalsy();
}
}
});
@@ -75,15 +82,15 @@ describe('CdkFlatTreeControl', () => {
for (let i = 0; i < numNodes; i++) {
expect(treeControl.getLevel(nodes[i]))
- .toBe(1, `Expec node[${i}]'s level to be 1`);
+ .withContext(`Expec node[${i}]'s level to be 1`).toBe(1);
for (let j = 0; j < numChildren; j++) {
expect(treeControl.getLevel(nodes[i].children[j]))
- .toBe(2, `Expect node[${i}]'s child[${j}] to be not expandable`);
+ .withContext(`Expect node[${i}]'s child[${j}] to be not expandable`).toBe(2);
for (let k = 0; k < numGrandChildren; k++) {
expect(treeControl.getLevel(nodes[i].children[j].children[k]))
- .toBe(3, `Expect node[${i}]'s child[${j}] to be not expandable`);
+ .withContext(`Expect node[${i}]'s child[${j}] to be not expandable`).toBe(3);
}
}
}
@@ -102,16 +109,20 @@ describe('CdkFlatTreeControl', () => {
const expandedNodesNum = 1 + numChildren + numChildren * numGrandChildren;
expect(treeControl.expansionModel.selected.length)
- .toBe(expandedNodesNum, `Expect expanded ${expandedNodesNum} nodes`);
+ .withContext(`Expect expanded ${expandedNodesNum} nodes`).toBe(expandedNodesNum);
- expect(treeControl.isExpanded(nodes[1])).toBeTruthy('Expect second node to be expanded');
+ expect(treeControl.isExpanded(nodes[1]))
+ .withContext('Expect second node to be expanded')
+ .toBeTruthy();
for (let i = 0; i < numChildren; i++) {
expect(treeControl.isExpanded(nodes[1].children[i]))
- .toBeTruthy(`Expect second node's children to be expanded`);
+ .withContext(`Expect second node's children to be expanded`)
+ .toBeTruthy();
for (let j = 0; j < numGrandChildren; j++) {
expect(treeControl.isExpanded(nodes[1].children[i].children[j]))
- .toBeTruthy(`Expect second node grand children to be not expanded`);
+ .withContext(`Expect second node grand children to be not expanded`)
+ .toBeTruthy();
}
}
@@ -130,14 +141,15 @@ describe('CdkFlatTreeControl', () => {
treeControl.collapseAll();
- expect(treeControl.expansionModel.selected.length).toBe(0, `Expect no expanded nodes`);
+ expect(treeControl.expansionModel.selected.length)
+ .withContext(`Expect no expanded nodes`).toBe(0);
treeControl.expandAll();
const totalNumber = numNodes + numNodes * numChildren
+ numNodes * numChildren * numGrandChildren;
expect(treeControl.expansionModel.selected.length)
- .toBe(totalNumber, `Expect ${totalNumber} expanded nodes`);
+ .withContext(`Expect ${totalNumber} expanded nodes`).toBe(totalNumber);
});
});
@@ -150,12 +162,14 @@ describe('CdkFlatTreeControl', () => {
treeControl.trackBy = (node: TestData) => `${node.a} ${node.b} ${node.c}`;
treeControl.expand(secondNode);
- expect(treeControl.isExpanded(secondNode)).toBeTruthy('Expect second node to be expanded');
+ expect(treeControl.isExpanded(secondNode))
+ .withContext('Expect second node to be expanded').toBeTruthy();
// Replace the second node with a brand new instance with same hash
nodes[1] = new TestData(
secondNode.a, secondNode.b, secondNode.c, secondNode.level, secondNode.children);
- expect(treeControl.isExpanded(nodes[1])).toBeTruthy('Expect second node to still be expanded');
+ expect(treeControl.isExpanded(nodes[1]))
+ .withContext('Expect second node to still be expanded').toBeTruthy();
});
});
diff --git a/src/cdk/tree/control/nested-tree-control.spec.ts b/src/cdk/tree/control/nested-tree-control.spec.ts
index eb38072e610d..d426acdfe30a 100644
--- a/src/cdk/tree/control/nested-tree-control.spec.ts
+++ b/src/cdk/tree/control/nested-tree-control.spec.ts
@@ -22,30 +22,34 @@ describe('CdkNestedTreeControl', () => {
treeControl.expand(node);
- expect(treeControl.isExpanded(node)).toBeTruthy('Expect second node to be expanded');
+ expect(treeControl.isExpanded(node))
+ .withContext('Expect second node to be expanded').toBeTruthy();
expect(treeControl.expansionModel.selected)
- .toContain(node, 'Expect second node in expansionModel');
+ .withContext('Expect second node in expansionModel').toContain(node);
expect(treeControl.expansionModel.selected.length)
- .toBe(1, 'Expect only second node in expansionModel');
+ .withContext('Expect only second node in expansionModel').toBe(1);
treeControl.toggle(sixthNode);
- expect(treeControl.isExpanded(node)).toBeTruthy('Expect second node to stay expanded');
+ expect(treeControl.isExpanded(node))
+ .withContext('Expect second node to stay expanded').toBeTruthy();
expect(treeControl.expansionModel.selected)
- .toContain(sixthNode, 'Expect sixth node in expansionModel');
+ .withContext('Expect sixth node in expansionModel').toContain(sixthNode);
expect(treeControl.expansionModel.selected)
- .toContain(node, 'Expect second node in expansionModel');
+ .withContext('Expect second node in expansionModel').toContain(node);
expect(treeControl.expansionModel.selected.length)
- .toBe(2, 'Expect two dataNodes in expansionModel');
+ .withContext('Expect two dataNodes in expansionModel').toBe(2);
treeControl.collapse(node);
- expect(treeControl.isExpanded(node)).toBeFalsy('Expect second node to be collapsed');
+ expect(treeControl.isExpanded(node))
+ .withContext('Expect second node to be collapsed').toBeFalsy();
expect(treeControl.expansionModel.selected.length)
- .toBe(1, 'Expect one node in expansionModel');
- expect(treeControl.isExpanded(sixthNode)).toBeTruthy('Expect sixth node to stay expanded');
+ .withContext('Expect one node in expansionModel').toBe(1);
+ expect(treeControl.isExpanded(sixthNode))
+ .withContext('Expect sixth node to stay expanded').toBeTruthy();
expect(treeControl.expansionModel.selected)
- .toContain(sixthNode, 'Expect sixth node in expansionModel');
+ .withContext('Expect sixth node in expansionModel').toContain(sixthNode);
});
it('should toggle descendants correctly', () => {
@@ -59,16 +63,19 @@ describe('CdkNestedTreeControl', () => {
const expandedNodesNum = 1 + numChildren + numChildren * numGrandChildren;
expect(treeControl.expansionModel.selected.length)
- .toBe(expandedNodesNum, `Expect expanded ${expandedNodesNum} nodes`);
+ .withContext(`Expect expanded ${expandedNodesNum} nodes`).toBe(expandedNodesNum);
- expect(treeControl.isExpanded(nodes[1])).toBeTruthy('Expect second node to be expanded');
+ expect(treeControl.isExpanded(nodes[1]))
+ .withContext('Expect second node to be expanded').toBeTruthy();
for (let i = 0; i < numChildren; i++) {
expect(treeControl.isExpanded(nodes[1].children[i]))
- .toBeTruthy(`Expect second node's children to be expanded`);
+ .withContext(`Expect second node's children to be expanded`)
+ .toBeTruthy();
for (let j = 0; j < numGrandChildren; j++) {
expect(treeControl.isExpanded(nodes[1].children[i].children[j]))
- .toBeTruthy(`Expect second node grand children to be expanded`);
+ .withContext(`Expect second node grand children to be expanded`)
+ .toBeTruthy();
}
}
});
@@ -84,14 +91,15 @@ describe('CdkNestedTreeControl', () => {
treeControl.collapseAll();
- expect(treeControl.expansionModel.selected.length).toBe(0, `Expect no expanded nodes`);
+ expect(treeControl.expansionModel.selected.length)
+ .withContext(`Expect no expanded nodes`).toBe(0);
treeControl.expandAll();
const totalNumber = numNodes + numNodes * numChildren
+ numNodes * numChildren * numGrandChildren;
expect(treeControl.expansionModel.selected.length)
- .toBe(totalNumber, `Expect ${totalNumber} expanded nodes`);
+ .withContext(`Expect ${totalNumber} expanded nodes`).toBe(totalNumber);
});
// Note that this needs to be `fakeAsync` in order to
@@ -124,30 +132,34 @@ describe('CdkNestedTreeControl', () => {
treeControl.expand(node);
- expect(treeControl.isExpanded(node)).toBeTruthy('Expect second node to be expanded');
+ expect(treeControl.isExpanded(node))
+ .withContext('Expect second node to be expanded').toBeTruthy();
expect(treeControl.expansionModel.selected)
- .toContain(node, 'Expect second node in expansionModel');
+ .withContext('Expect second node in expansionModel').toContain(node);
expect(treeControl.expansionModel.selected.length)
- .toBe(1, 'Expect only second node in expansionModel');
+ .withContext('Expect only second node in expansionModel').toBe(1);
treeControl.toggle(sixthNode);
- expect(treeControl.isExpanded(node)).toBeTruthy('Expect second node to stay expanded');
+ expect(treeControl.isExpanded(node))
+ .withContext('Expect second node to stay expanded').toBeTruthy();
expect(treeControl.expansionModel.selected)
- .toContain(sixthNode, 'Expect sixth node in expansionModel');
+ .withContext('Expect sixth node in expansionModel').toContain(sixthNode);
expect(treeControl.expansionModel.selected)
- .toContain(node, 'Expect second node in expansionModel');
+ .withContext('Expect second node in expansionModel').toContain(node);
expect(treeControl.expansionModel.selected.length)
- .toBe(2, 'Expect two dataNodes in expansionModel');
+ .withContext('Expect two dataNodes in expansionModel').toBe(2);
treeControl.collapse(node);
- expect(treeControl.isExpanded(node)).toBeFalsy('Expect second node to be collapsed');
+ expect(treeControl.isExpanded(node))
+ .withContext('Expect second node to be collapsed').toBeFalsy();
expect(treeControl.expansionModel.selected.length)
- .toBe(1, 'Expect one node in expansionModel');
- expect(treeControl.isExpanded(sixthNode)).toBeTruthy('Expect sixth node to stay expanded');
+ .withContext('Expect one node in expansionModel').toBe(1);
+ expect(treeControl.isExpanded(sixthNode))
+ .withContext('Expect sixth node to stay expanded').toBeTruthy();
expect(treeControl.expansionModel.selected)
- .toContain(sixthNode, 'Expect sixth node in expansionModel');
+ .withContext('Expect sixth node in expansionModel').toContain(sixthNode);
});
it('should toggle descendants correctly', () => {
@@ -161,16 +173,19 @@ describe('CdkNestedTreeControl', () => {
const expandedNodesNum = 1 + numChildren + numChildren * numGrandChildren;
expect(treeControl.expansionModel.selected.length)
- .toBe(expandedNodesNum, `Expect expanded ${expandedNodesNum} nodes`);
+ .withContext(`Expect expanded ${expandedNodesNum} nodes`).toBe(expandedNodesNum);
- expect(treeControl.isExpanded(nodes[1])).toBeTruthy('Expect second node to be expanded');
+ expect(treeControl.isExpanded(nodes[1]))
+ .withContext('Expect second node to be expanded').toBeTruthy();
for (let i = 0; i < numChildren; i++) {
expect(treeControl.isExpanded(nodes[1].children[i]))
- .toBeTruthy(`Expect second node's children to be expanded`);
+ .withContext(`Expect second node's children to be expanded`)
+ .toBeTruthy();
for (let j = 0; j < numGrandChildren; j++) {
expect(treeControl.isExpanded(nodes[1].children[i].children[j]))
- .toBeTruthy(`Expect second node grand children to be expanded`);
+ .withContext(`Expect second node grand children to be expanded`)
+ .toBeTruthy();
}
}
});
@@ -186,14 +201,15 @@ describe('CdkNestedTreeControl', () => {
treeControl.collapseAll();
- expect(treeControl.expansionModel.selected.length).toBe(0, `Expect no expanded nodes`);
+ expect(treeControl.expansionModel.selected.length)
+ .withContext(`Expect no expanded nodes`).toBe(0);
treeControl.expandAll();
const totalNumber = numNodes + (numNodes * numChildren)
+ (numNodes * numChildren * numGrandChildren);
expect(treeControl.expansionModel.selected.length)
- .toBe(totalNumber, `Expect ${totalNumber} expanded nodes`);
+ .withContext(`Expect ${totalNumber} expanded nodes`).toBe(totalNumber);
});
});
});
@@ -207,12 +223,16 @@ describe('CdkNestedTreeControl', () => {
treeControl.dataNodes = nodes;
treeControl.expand(secondNode);
- expect(treeControl.isExpanded(secondNode)).toBeTruthy('Expect second node to be expanded');
+ expect(treeControl.isExpanded(secondNode))
+ .withContext('Expect second node to be expanded')
+ .toBeTruthy();
// Replace the second node with a brand new instance with same hash
nodes[1] = new TestData(
secondNode.a, secondNode.b, secondNode.c, secondNode.level, secondNode.children);
- expect(treeControl.isExpanded(nodes[1])).toBeTruthy('Expect second node to still be expanded');
+ expect(treeControl.isExpanded(nodes[1]))
+ .withContext('Expect second node to still be expanded')
+ .toBeTruthy();
});
});
diff --git a/src/cdk/tree/tree.spec.ts b/src/cdk/tree/tree.spec.ts
index f0c0dcdd6d30..a1535c83d6f2 100644
--- a/src/cdk/tree/tree.spec.ts
+++ b/src/cdk/tree/tree.spec.ts
@@ -108,7 +108,7 @@ describe('CdkTree', () => {
it('with rendered dataNodes', () => {
const nodes = getNodes(treeElement);
- expect(nodes).toBeDefined('Expect nodes to be defined');
+ expect(nodes).withContext('Expect nodes to be defined').toBeDefined();
expect(nodes[0].classList).toContain('customNodeClass');
});
@@ -242,7 +242,7 @@ describe('CdkTree', () => {
expect(dataSource.data.length).toBe(3);
expect(component.treeControl.expansionModel.selected.length)
- .toBe(0, `Expect no expanded node`);
+ .withContext(`Expect no expanded node`).toBe(0);
component.toggleRecursively = false;
let data = dataSource.data;
@@ -262,21 +262,21 @@ describe('CdkTree', () => {
fixture.detectChanges();
expect(component.treeControl.expansionModel.selected.length)
- .toBe(1, `Expect node expanded`);
+ .withContext(`Expect node expanded`).toBe(1);
expect(component.treeControl.expansionModel.selected[0]).toBe(data[2]);
(getNodes(treeElement)[2] as HTMLElement).click();
fixture.detectChanges();
expect(component.treeControl.expansionModel.selected.length)
- .toBe(0, `Expect node collapsed`);
+ .withContext(`Expect node collapsed`).toBe(0);
});
it('should expand/collapse the node recursively', () => {
expect(dataSource.data.length).toBe(3);
expect(component.treeControl.expansionModel.selected.length)
- .toBe(0, `Expect no expanded node`);
+ .withContext(`Expect no expanded node`).toBe(0);
let data = dataSource.data;
dataSource.addChild(data[2]);
@@ -294,17 +294,17 @@ describe('CdkTree', () => {
fixture.detectChanges();
expect(component.treeControl.expansionModel.selected.length)
- .toBe(2, `Expect nodes expanded`);
+ .withContext(`Expect nodes expanded`).toBe(2);
expect(component.treeControl.expansionModel.selected[0])
- .toBe(data[2], `Expect parent node expanded`);
+ .withContext(`Expect parent node expanded`).toBe(data[2]);
expect(component.treeControl.expansionModel.selected[1])
- .toBe(data[3], `Expected child node expanded`);
+ .withContext(`Expected child node expanded`).toBe(data[3]);
(getNodes(treeElement)[2] as HTMLElement).click();
fixture.detectChanges();
expect(component.treeControl.expansionModel.selected.length)
- .toBe(0, `Expect node collapsed`);
+ .withContext(`Expect node collapsed`).toBe(0);
});
});
@@ -550,7 +550,7 @@ describe('CdkTree', () => {
it('with rendered dataNodes', () => {
const nodes = getNodes(treeElement);
- expect(nodes).toBeDefined('Expect nodes to be defined');
+ expect(nodes).withContext('Expect nodes to be defined').toBeDefined();
expect(nodes[0].classList).toContain('customNodeClass');
});
@@ -745,7 +745,7 @@ describe('CdkTree', () => {
fixture.detectChanges();
expect(component.treeControl.expansionModel.selected.length)
- .toBe(1, `Expect node expanded`);
+ .withContext(`Expect node expanded`).toBe(1);
expectNestedTreeToMatch(treeElement,
[`topping_1 - cheese_1 + base_1`],
[`topping_2 - cheese_2 + base_2`],
@@ -760,13 +760,13 @@ describe('CdkTree', () => {
[`topping_2 - cheese_2 + base_2`],
[`topping_3 - cheese_3 + base_3`]);
expect(component.treeControl.expansionModel.selected.length)
- .toBe(0, `Expect node collapsed`);
+ .withContext(`Expect node collapsed`).toBe(0);
(getNodes(treeElement)[1] as HTMLElement).click();
fixture.detectChanges();
expect(component.treeControl.expansionModel.selected.length)
- .toBe(1, `Expect node expanded`);
+ .withContext(`Expect node expanded`).toBe(1);
expectNestedTreeToMatch(treeElement,
[`topping_1 - cheese_1 + base_1`],
[`topping_2 - cheese_2 + base_2`],
@@ -789,7 +789,7 @@ describe('CdkTree', () => {
fixture.detectChanges();
expect(component.treeControl.expansionModel.selected.length)
- .toBe(3, `Expect node expanded`);
+ .withContext(`Expect node expanded`).toBe(3);
expectNestedTreeToMatch(treeElement,
[`topping_1 - cheese_1 + base_1`],
[`topping_2 - cheese_2 + base_2`],
@@ -801,7 +801,7 @@ describe('CdkTree', () => {
fixture.detectChanges();
expect(component.treeControl.expansionModel.selected.length)
- .toBe(0, `Expect node collapsed`);
+ .withContext(`Expect node collapsed`).toBe(0);
expectNestedTreeToMatch(treeElement,
[`topping_1 - cheese_1 + base_1`],
[`topping_2 - cheese_2 + base_2`],
diff --git a/src/material-date-fns-adapter/adapter/date-fns-adapter.spec.ts b/src/material-date-fns-adapter/adapter/date-fns-adapter.spec.ts
index 7d0337a9d063..1885eda5eda1 100644
--- a/src/material-date-fns-adapter/adapter/date-fns-adapter.spec.ts
+++ b/src/material-date-fns-adapter/adapter/date-fns-adapter.spec.ts
@@ -144,7 +144,7 @@ describe('DateFnsAdapter', () => {
it("should get today's date", () => {
expect(adapter.sameDate(adapter.today(), new Date()))
- .toBe(true, "should be equal to today's date");
+ .withContext("should be equal to today's date").toBe(true);
});
it('should parse string according to given format', () => {
@@ -180,7 +180,7 @@ describe('DateFnsAdapter', () => {
expect(d).not.toBeNull();
expect(adapter.isDateInstance(d)).toBe(true);
expect(adapter.isValid(d as Date))
- .toBe(false, 'Expected to parse as "invalid date" object');
+ .withContext('Expected to parse as "invalid date" object').toBe(false);
});
it('should format date according to given format', () => {
@@ -322,8 +322,8 @@ function stripDirectionalityCharacters(str: string) {
}
function assertValidDate(adapter: DateAdapter, d: Date | null, valid: boolean) {
- expect(adapter.isDateInstance(d)).not.toBeNull(`Expected ${d} to be a date instance`);
- expect(adapter.isValid(d!)).toBe(valid,
- `Expected ${d} to be ${valid ? 'valid' : 'invalid'},` +
- ` but was ${valid ? 'invalid' : 'valid'}`);
+ expect(adapter.isDateInstance(d)).not
+ .withContext(`Expected ${d} to be a date instance`).toBeNull();
+ expect(adapter.isValid(d!)).withContext(`Expected ${d} to be ${valid ? 'valid' : 'invalid'},` +
+ ` but was ${valid ? 'invalid' : 'valid'}`).toBe(valid);
}
diff --git a/src/material-experimental/mdc-autocomplete/autocomplete.spec.ts b/src/material-experimental/mdc-autocomplete/autocomplete.spec.ts
index 9b52a7bbdc12..f9e821cd9db2 100644
--- a/src/material-experimental/mdc-autocomplete/autocomplete.spec.ts
+++ b/src/material-experimental/mdc-autocomplete/autocomplete.spec.ts
@@ -106,17 +106,17 @@ describe('MDC-based MatAutocomplete', () => {
it('should open the panel when the input is focused', () => {
expect(fixture.componentInstance.trigger.panelOpen)
- .toBe(false, `Expected panel state to start out closed.`);
+ .withContext(`Expected panel state to start out closed.`).toBe(false);
dispatchFakeEvent(input, 'focusin');
fixture.detectChanges();
expect(fixture.componentInstance.trigger.panelOpen)
- .toBe(true, `Expected panel state to read open when input is focused.`);
+ .withContext(`Expected panel state to read open when input is focused.`).toBe(true);
expect(overlayContainerElement.textContent)
- .toContain('Alabama', `Expected panel to display when input is focused.`);
+ .withContext(`Expected panel to display when input is focused.`).toContain('Alabama');
expect(overlayContainerElement.textContent)
- .toContain('California', `Expected panel to display when input is focused.`);
+ .withContext(`Expected panel to display when input is focused.`).toContain('California');
});
it('should not open the panel on focus if the input is readonly', fakeAsync(() => {
@@ -124,12 +124,14 @@ describe('MDC-based MatAutocomplete', () => {
input.readOnly = true;
fixture.detectChanges();
- expect(trigger.panelOpen).toBe(false, 'Expected panel state to start out closed.');
+ expect(trigger.panelOpen)
+ .withContext('Expected panel state to start out closed.').toBe(false);
dispatchFakeEvent(input, 'focusin');
flush();
fixture.detectChanges();
- expect(trigger.panelOpen).toBe(false, 'Expected panel to stay closed.');
+ expect(trigger.panelOpen)
+ .withContext('Expected panel to stay closed.').toBe(false);
}));
it('should not open using the arrow keys when the input is readonly', fakeAsync(() => {
@@ -137,27 +139,31 @@ describe('MDC-based MatAutocomplete', () => {
input.readOnly = true;
fixture.detectChanges();
- expect(trigger.panelOpen).toBe(false, 'Expected panel state to start out closed.');
+ expect(trigger.panelOpen)
+ .withContext('Expected panel state to start out closed.').toBe(false);
dispatchKeyboardEvent(input, 'keydown', DOWN_ARROW);
flush();
fixture.detectChanges();
- expect(trigger.panelOpen).toBe(false, 'Expected panel to stay closed.');
+ expect(trigger.panelOpen)
+ .withContext('Expected panel to stay closed.').toBe(false);
}));
it('should open the panel programmatically', () => {
expect(fixture.componentInstance.trigger.panelOpen)
- .toBe(false, `Expected panel state to start out closed.`);
+ .withContext(`Expected panel state to start out closed.`).toBe(false);
fixture.componentInstance.trigger.openPanel();
fixture.detectChanges();
expect(fixture.componentInstance.trigger.panelOpen)
- .toBe(true, `Expected panel state to read open when opened programmatically.`);
+ .withContext(`Expected panel state to read open when opened programmatically.`).toBe(true);
expect(overlayContainerElement.textContent)
- .toContain('Alabama', `Expected panel to display when opened programmatically.`);
+ .withContext(`Expected panel to display when opened programmatically.`)
+ .toContain('Alabama');
expect(overlayContainerElement.textContent)
- .toContain('California', `Expected panel to display when opened programmatically.`);
+ .withContext(`Expected panel to display when opened programmatically.`)
+ .toContain('California');
});
it('should show the panel when the first open is after the initial zone stabilization',
@@ -170,7 +176,7 @@ describe('MDC-based MatAutocomplete', () => {
Promise.resolve().then(() => {
expect(fixture.componentInstance.panel.showPanel)
- .toBe(true, `Expected panel to be visible.`);
+ .withContext(`Expected panel to be visible.`).toBe(true);
});
});
}));
@@ -183,9 +189,9 @@ describe('MDC-based MatAutocomplete', () => {
tick();
expect(fixture.componentInstance.trigger.panelOpen)
- .toBe(false, `Expected clicking outside the panel to set its state to closed.`);
+ .withContext(`Expected clicking outside the panel to set its state to closed.`).toBe(false);
expect(overlayContainerElement.textContent)
- .toEqual('', `Expected clicking outside the panel to close the panel.`);
+ .withContext(`Expected clicking outside the panel to close the panel.`).toEqual('');
}));
it('should close the panel when the user clicks away via auxilliary button', fakeAsync(() => {
@@ -196,9 +202,9 @@ describe('MDC-based MatAutocomplete', () => {
tick();
expect(fixture.componentInstance.trigger.panelOpen)
- .toBe(false, `Expected clicking outside the panel to set its state to closed.`);
+ .withContext(`Expected clicking outside the panel to set its state to closed.`).toBe(false);
expect(overlayContainerElement.textContent)
- .toEqual('', `Expected clicking outside the panel to close the panel.`);
+ .withContext(`Expected clicking outside the panel to close the panel.`).toEqual('');
}));
it('should close the panel when the user taps away on a touch device', fakeAsync(() => {
@@ -208,9 +214,9 @@ describe('MDC-based MatAutocomplete', () => {
dispatchFakeEvent(document, 'touchend');
expect(fixture.componentInstance.trigger.panelOpen)
- .toBe(false, `Expected tapping outside the panel to set its state to closed.`);
+ .withContext(`Expected tapping outside the panel to set its state to closed.`).toBe(false);
expect(overlayContainerElement.textContent)
- .toEqual('', `Expected tapping outside the panel to close the panel.`);
+ .withContext(`Expected tapping outside the panel to close the panel.`).toEqual('');
}));
it('should close the panel when an option is clicked', fakeAsync(() => {
@@ -224,9 +230,9 @@ describe('MDC-based MatAutocomplete', () => {
tick();
expect(fixture.componentInstance.trigger.panelOpen)
- .toBe(false, `Expected clicking an option to set the panel state to closed.`);
+ .withContext(`Expected clicking an option to set the panel state to closed.`).toBe(false);
expect(overlayContainerElement.textContent)
- .toEqual('', `Expected clicking an option to close the panel.`);
+ .withContext(`Expected clicking an option to close the panel.`).toEqual('');
}));
it('should close the panel when a newly created option is clicked', fakeAsync(() => {
@@ -257,9 +263,10 @@ describe('MDC-based MatAutocomplete', () => {
tick();
expect(fixture.componentInstance.trigger.panelOpen)
- .toBe(false, `Expected clicking a new option to set the panel state to closed.`);
+ .withContext(`Expected clicking a new option to set the panel state to closed.`)
+ .toBe(false);
expect(overlayContainerElement.textContent)
- .toEqual('', `Expected clicking a new option to close the panel.`);
+ .withContext(`Expected clicking a new option to close the panel.`).toEqual('');
}));
it('should close the panel programmatically', fakeAsync(() => {
@@ -271,9 +278,10 @@ describe('MDC-based MatAutocomplete', () => {
tick();
expect(fixture.componentInstance.trigger.panelOpen)
- .toBe(false, `Expected closing programmatically to set the panel state to closed.`);
+ .withContext(`Expected closing programmatically to set the panel state to closed.`)
+ .toBe(false);
expect(overlayContainerElement.textContent)
- .toEqual('', `Expected closing programmatically to close the panel.`);
+ .withContext(`Expected closing programmatically to close the panel.`).toEqual('');
}));
it('should not throw when attempting to close the panel of a destroyed autocomplete', () => {
@@ -294,7 +302,8 @@ describe('MDC-based MatAutocomplete', () => {
overlayContainerElement.querySelector('.mat-mdc-autocomplete-panel') as HTMLElement;
expect(panel.classList)
- .toContain('mat-mdc-autocomplete-visible', `Expected panel to start out visible.`);
+ .withContext(`Expected panel to start out visible.`)
+ .toContain('mat-mdc-autocomplete-visible');
// Filter down the option list such that no options match the value
typeInElement(input, 'af');
@@ -303,13 +312,14 @@ describe('MDC-based MatAutocomplete', () => {
fixture.detectChanges();
expect(panel.classList)
- .toContain('mat-mdc-autocomplete-hidden', `Expected panel to hide itself when empty.`);
+ .withContext(`Expected panel to hide itself when empty.`)
+ .toContain('mat-mdc-autocomplete-hidden');
}));
it('should keep the label floating until the panel closes', fakeAsync(() => {
fixture.componentInstance.trigger.openPanel();
expect(fixture.componentInstance.formField.floatLabel)
- .toEqual('always', 'Expected label to float as soon as panel opens.');
+ .withContext('Expected label to float as soon as panel opens.').toEqual('always');
zone.simulateZoneExit();
fixture.detectChanges();
@@ -320,19 +330,19 @@ describe('MDC-based MatAutocomplete', () => {
fixture.detectChanges();
expect(fixture.componentInstance.formField.floatLabel)
- .toEqual('auto', 'Expected label to return to auto state after panel closes.');
+ .withContext('Expected label to return to auto state after panel closes.').toEqual('auto');
}));
it('should not open the panel when the `input` event is invoked on a non-focused input', () => {
expect(fixture.componentInstance.trigger.panelOpen)
- .toBe(false, `Expected panel state to start out closed.`);
+ .withContext(`Expected panel state to start out closed.`).toBe(false);
input.value = 'Alabama';
dispatchFakeEvent(input, 'input');
fixture.detectChanges();
expect(fixture.componentInstance.trigger.panelOpen)
- .toBe(false, `Expected panel state to stay closed.`);
+ .withContext(`Expected panel state to stay closed.`).toBe(false);
});
it('should not mess with label placement if set to never', fakeAsync(() => {
@@ -341,7 +351,7 @@ describe('MDC-based MatAutocomplete', () => {
fixture.componentInstance.trigger.openPanel();
expect(fixture.componentInstance.formField.floatLabel)
- .toEqual('never', 'Expected label to stay static.');
+ .withContext('Expected label to stay static.').toEqual('never');
flush();
fixture.detectChanges();
@@ -351,7 +361,7 @@ describe('MDC-based MatAutocomplete', () => {
fixture.detectChanges();
expect(fixture.componentInstance.formField.floatLabel)
- .toEqual('never', 'Expected label to stay in static state after close.');
+ .withContext('Expected label to stay in static state after close.').toEqual('never');
}));
it('should not mess with label placement if set to always', fakeAsync(() => {
@@ -360,7 +370,7 @@ describe('MDC-based MatAutocomplete', () => {
fixture.componentInstance.trigger.openPanel();
expect(fixture.componentInstance.formField.floatLabel)
- .toEqual('always', 'Expected label to stay elevated on open.');
+ .withContext('Expected label to stay elevated on open.').toEqual('always');
flush();
fixture.detectChanges();
@@ -370,7 +380,7 @@ describe('MDC-based MatAutocomplete', () => {
fixture.detectChanges();
expect(fixture.componentInstance.formField.floatLabel)
- .toEqual('always', 'Expected label to stay elevated after close.');
+ .withContext('Expected label to stay elevated after close.').toEqual('always');
}));
it('should toggle the visibility when typing and closing the panel', fakeAsync(() => {
@@ -379,7 +389,7 @@ describe('MDC-based MatAutocomplete', () => {
fixture.detectChanges();
expect(overlayContainerElement.querySelector('.mat-mdc-autocomplete-panel')!.classList)
- .toContain('mat-mdc-autocomplete-visible', 'Expected panel to be visible.');
+ .withContext('Expected panel to be visible.').toContain('mat-mdc-autocomplete-visible');
typeInElement(input, 'x');
fixture.detectChanges();
@@ -387,7 +397,7 @@ describe('MDC-based MatAutocomplete', () => {
fixture.detectChanges();
expect(overlayContainerElement.querySelector('.mat-mdc-autocomplete-panel')!.classList)
- .toContain('mat-mdc-autocomplete-hidden', 'Expected panel to be hidden.');
+ .withContext('Expected panel to be hidden.').toContain('mat-mdc-autocomplete-hidden');
fixture.componentInstance.trigger.closePanel();
fixture.detectChanges();
@@ -402,7 +412,7 @@ describe('MDC-based MatAutocomplete', () => {
fixture.detectChanges();
expect(overlayContainerElement.querySelector('.mat-mdc-autocomplete-panel')!.classList)
- .toContain('mat-mdc-autocomplete-visible', 'Expected panel to be visible.');
+ .withContext('Expected panel to be visible.').toContain('mat-mdc-autocomplete-visible');
}));
it('should animate the label when the input is focused', () => {
@@ -502,7 +512,7 @@ describe('MDC-based MatAutocomplete', () => {
it('should not be able to open the panel if the autocomplete is disabled', () => {
expect(fixture.componentInstance.trigger.panelOpen)
- .toBe(false, `Expected panel state to start out closed.`);
+ .withContext(`Expected panel state to start out closed.`).toBe(false);
fixture.componentInstance.autocompleteDisabled = true;
fixture.detectChanges();
@@ -511,7 +521,7 @@ describe('MDC-based MatAutocomplete', () => {
fixture.detectChanges();
expect(fixture.componentInstance.trigger.panelOpen)
- .toBe(false, `Expected panel to remain closed.`);
+ .withContext(`Expected panel to remain closed.`).toBe(false);
});
it('should continue to update the model if the autocomplete is disabled', () => {
@@ -545,13 +555,13 @@ describe('MDC-based MatAutocomplete', () => {
zone.simulateZoneExit();
expect(fixture.componentInstance.trigger.panelOpen)
- .toBe(true, 'Expected panel to be opened on focus.');
+ .withContext('Expected panel to be opened on focus.').toBe(true);
input.click();
fixture.detectChanges();
expect(fixture.componentInstance.trigger.panelOpen)
- .toBe(true, 'Expected panel to remain opened after clicking on the input.');
+ .withContext('Expected panel to remain opened after clicking on the input.').toBe(true);
}));
it('should not close the panel when clicking on the input inside shadow DOM', fakeAsync(() => {
@@ -569,13 +579,13 @@ describe('MDC-based MatAutocomplete', () => {
zone.simulateZoneExit();
expect(fixture.componentInstance.trigger.panelOpen)
- .toBe(true, 'Expected panel to be opened on focus.');
+ .withContext('Expected panel to be opened on focus.').toBe(true);
input.click();
fixture.detectChanges();
expect(fixture.componentInstance.trigger.panelOpen)
- .toBe(true, 'Expected panel to remain opened after clicking on the input.');
+ .withContext('Expected panel to remain opened after clicking on the input.').toBe(true);
}));
it('should have the correct text direction in RTL', () => {
@@ -657,13 +667,13 @@ describe('MDC-based MatAutocomplete', () => {
fixture.detectChanges();
expect(fixture.componentInstance.stateCtrl.value)
- .toEqual('a', 'Expected control value to be updated as user types.');
+ .withContext('Expected control value to be updated as user types.').toEqual('a');
typeInElement(input, 'l');
fixture.detectChanges();
expect(fixture.componentInstance.stateCtrl.value)
- .toEqual('al', 'Expected control value to be updated as user types.');
+ .withContext('Expected control value to be updated as user types.').toEqual('al');
});
it('should update control value when autofilling', () => {
@@ -675,7 +685,7 @@ describe('MDC-based MatAutocomplete', () => {
fixture.detectChanges();
expect(fixture.componentInstance.stateCtrl.value)
- .toBe('Alabama', 'Expected value to be propagated to the form control.');
+ .withContext('Expected value to be propagated to the form control.').toBe('Alabama');
});
it('should update control value when option is selected with option value', fakeAsync(() => {
@@ -689,8 +699,8 @@ describe('MDC-based MatAutocomplete', () => {
fixture.detectChanges();
expect(fixture.componentInstance.stateCtrl.value)
- .toEqual({code: 'CA', name: 'California'},
- 'Expected control value to equal the selected option value.');
+ .withContext('Expected control value to equal the selected option value.')
+ .toEqual({ code: 'CA', name: 'California' });
}));
it('should update the control back to a string if user types after an option is selected',
@@ -710,7 +720,7 @@ describe('MDC-based MatAutocomplete', () => {
tick();
expect(fixture.componentInstance.stateCtrl.value)
- .toEqual('Californi', 'Expected control value to revert back to string.');
+ .withContext('Expected control value to revert back to string.').toEqual('Californi');
}));
it('should fill the text field with display value when an option is selected', fakeAsync(() => {
@@ -724,7 +734,7 @@ describe('MDC-based MatAutocomplete', () => {
fixture.detectChanges();
expect(input.value)
- .toContain('California', `Expected text field to fill with selected value.`);
+ .withContext(`Expected text field to fill with selected value.`).toContain('California');
}));
it('should fill the text field with value if displayWith is not set', fakeAsync(() => {
@@ -742,7 +752,8 @@ describe('MDC-based MatAutocomplete', () => {
fixture.detectChanges();
expect(input.value)
- .toContain('test value', `Expected input to fall back to selected option's value.`);
+ .withContext(`Expected input to fall back to selected option's value.`)
+ .toContain('test value');
}));
it('should fill the text field correctly if value is set to obj programmatically',
@@ -753,7 +764,8 @@ describe('MDC-based MatAutocomplete', () => {
fixture.detectChanges();
expect(input.value)
- .toContain('Alabama', `Expected input to fill with matching option's viewValue.`);
+ .withContext(`Expected input to fill with matching option's viewValue.`)
+ .toContain('Alabama');
}));
it('should clear the text field if value is reset programmatically', fakeAsync(() => {
@@ -767,7 +779,8 @@ describe('MDC-based MatAutocomplete', () => {
fixture.detectChanges();
tick();
- expect(input.value).toEqual('', `Expected input value to be empty after reset.`);
+ expect(input.value)
+ .withContext(`Expected input value to be empty after reset.`).toEqual('');
}));
it('should disable input in view when disabled programmatically', () => {
@@ -775,33 +788,35 @@ describe('MDC-based MatAutocomplete', () => {
fixture.debugElement.query(By.css('.mat-mdc-form-field'))!.nativeElement;
expect(input.disabled)
- .toBe(false, `Expected input to start out enabled in view.`);
+ .withContext(`Expected input to start out enabled in view.`).toBe(false);
expect(formFieldElement.classList.contains('mat-form-field-disabled'))
- .toBe(false, `Expected input underline to start out with normal styles.`);
+ .withContext(`Expected input underline to start out with normal styles.`).toBe(false);
fixture.componentInstance.stateCtrl.disable();
fixture.detectChanges();
expect(input.disabled)
- .toBe(true, `Expected input to be disabled in view when disabled programmatically.`);
+ .withContext(`Expected input to be disabled in view when disabled programmatically.`)
+ .toBe(true);
expect(formFieldElement.classList.contains('mat-form-field-disabled'))
- .toBe(true, `Expected input underline to display disabled styles.`);
+ .withContext(`Expected input underline to display disabled styles.`).toBe(true);
});
it('should mark the autocomplete control as dirty as user types', () => {
expect(fixture.componentInstance.stateCtrl.dirty)
- .toBe(false, `Expected control to start out pristine.`);
+ .withContext(`Expected control to start out pristine.`).toBe(false);
typeInElement(input, 'a');
fixture.detectChanges();
expect(fixture.componentInstance.stateCtrl.dirty)
- .toBe(true, `Expected control to become dirty when the user types into the input.`);
+ .withContext(`Expected control to become dirty when the user types into the input.`)
+ .toBe(true);
});
it('should mark the autocomplete control as dirty when an option is selected', fakeAsync(() => {
expect(fixture.componentInstance.stateCtrl.dirty)
- .toBe(false, `Expected control to start out pristine.`);
+ .withContext(`Expected control to start out pristine.`).toBe(false);
fixture.componentInstance.trigger.openPanel();
fixture.detectChanges();
@@ -813,31 +828,32 @@ describe('MDC-based MatAutocomplete', () => {
fixture.detectChanges();
expect(fixture.componentInstance.stateCtrl.dirty)
- .toBe(true, `Expected control to become dirty when an option was selected.`);
+ .withContext(`Expected control to become dirty when an option was selected.`).toBe(true);
}));
it('should not mark the control dirty when the value is set programmatically', () => {
expect(fixture.componentInstance.stateCtrl.dirty)
- .toBe(false, `Expected control to start out pristine.`);
+ .withContext(`Expected control to start out pristine.`).toBe(false);
fixture.componentInstance.stateCtrl.setValue('AL');
fixture.detectChanges();
expect(fixture.componentInstance.stateCtrl.dirty)
- .toBe(false, `Expected control to stay pristine if value is set programmatically.`);
+ .withContext(`Expected control to stay pristine if value is set programmatically.`)
+ .toBe(false);
});
it('should mark the autocomplete control as touched on blur', () => {
fixture.componentInstance.trigger.openPanel();
fixture.detectChanges();
expect(fixture.componentInstance.stateCtrl.touched)
- .toBe(false, `Expected control to start out untouched.`);
+ .withContext(`Expected control to start out untouched.`).toBe(false);
dispatchFakeEvent(input, 'blur');
fixture.detectChanges();
expect(fixture.componentInstance.stateCtrl.touched)
- .toBe(true, `Expected control to become touched on blur.`);
+ .withContext(`Expected control to become touched on blur.`).toBe(true);
});
it('should disable the input when used with a value accessor and without `matInput`', () => {
@@ -891,11 +907,13 @@ describe('MDC-based MatAutocomplete', () => {
fixture.componentInstance.trigger._handleKeydown(DOWN_ARROW_EVENT);
expect(fixture.componentInstance.trigger.panelOpen)
- .toBe(true, `Expected panel state to stay open when DOWN key is pressed.`);
+ .withContext(`Expected panel state to stay open when DOWN key is pressed.`).toBe(true);
expect(overlayContainerElement.textContent)
- .toContain('Alabama', `Expected panel to keep displaying when DOWN key is pressed.`);
+ .withContext(`Expected panel to keep displaying when DOWN key is pressed.`)
+ .toContain('Alabama');
expect(overlayContainerElement.textContent)
- .toContain('California', `Expected panel to keep displaying when DOWN key is pressed.`);
+ .withContext(`Expected panel to keep displaying when DOWN key is pressed.`)
+ .toContain('California');
});
it('should set the active item to the first option when DOWN key is pressed', () => {
@@ -904,13 +922,13 @@ describe('MDC-based MatAutocomplete', () => {
overlayContainerElement.querySelectorAll('mat-option') as NodeListOf;
expect(componentInstance.trigger.panelOpen)
- .toBe(true, 'Expected first down press to open the pane.');
+ .withContext('Expected first down press to open the pane.').toBe(true);
componentInstance.trigger._handleKeydown(DOWN_ARROW_EVENT);
fixture.detectChanges();
expect(componentInstance.trigger.activeOption === componentInstance.options.first)
- .toBe(true, 'Expected first option to be active.');
+ .withContext('Expected first option to be active.').toBe(true);
expect(optionEls[0].classList).toContain('mat-mdc-option-active');
expect(optionEls[1].classList).not.toContain('mat-mdc-option-active');
@@ -918,7 +936,7 @@ describe('MDC-based MatAutocomplete', () => {
fixture.detectChanges();
expect(componentInstance.trigger.activeOption === componentInstance.options.toArray()[1])
- .toBe(true, 'Expected second option to be active.');
+ .withContext('Expected second option to be active.').toBe(true);
expect(optionEls[0].classList).not.toContain('mat-mdc-option-active');
expect(optionEls[1].classList).toContain('mat-mdc-option-active');
});
@@ -929,13 +947,13 @@ describe('MDC-based MatAutocomplete', () => {
overlayContainerElement.querySelectorAll('mat-option') as NodeListOf;
expect(componentInstance.trigger.panelOpen)
- .toBe(true, 'Expected first up press to open the pane.');
+ .withContext('Expected first up press to open the pane.').toBe(true);
componentInstance.trigger._handleKeydown(UP_ARROW_EVENT);
fixture.detectChanges();
expect(componentInstance.trigger.activeOption === componentInstance.options.last)
- .toBe(true, 'Expected last option to be active.');
+ .withContext('Expected last option to be active.').toBe(true);
expect(optionEls[10].classList).toContain('mat-mdc-option-active');
expect(optionEls[0].classList).not.toContain('mat-mdc-option-active');
@@ -943,7 +961,7 @@ describe('MDC-based MatAutocomplete', () => {
fixture.detectChanges();
expect(componentInstance.trigger.activeOption === componentInstance.options.first)
- .toBe(true, 'Expected first option to be active.');
+ .withContext('Expected first option to be active.').toBe(true);
expect(optionEls[0].classList).toContain('mat-mdc-option-active');
});
@@ -968,7 +986,7 @@ describe('MDC-based MatAutocomplete', () => {
overlayContainerElement.querySelectorAll('mat-option') as NodeListOf;
expect(componentInstance.trigger.activeOption === componentInstance.options.first)
- .toBe(true, 'Expected first option to be active.');
+ .withContext('Expected first option to be active.').toBe(true);
expect(optionEls[0].classList).toContain('mat-mdc-option-active');
expect(optionEls[1].classList).not.toContain('mat-mdc-option-active');
});
@@ -981,7 +999,8 @@ describe('MDC-based MatAutocomplete', () => {
fixture.componentInstance.trigger._handleKeydown(ENTER_EVENT);
fixture.detectChanges();
expect(input.value)
- .toContain('Alabama', `Expected text field to fill with selected value on ENTER.`);
+ .withContext(`Expected text field to fill with selected value on ENTER.`)
+ .toContain('Alabama');
}));
it('should prevent the default enter key action', fakeAsync(() => {
@@ -991,7 +1010,7 @@ describe('MDC-based MatAutocomplete', () => {
fixture.componentInstance.trigger._handleKeydown(ENTER_EVENT);
expect(ENTER_EVENT.defaultPrevented)
- .toBe(true, 'Expected the default action to have been prevented.');
+ .withContext('Expected the default action to have been prevented.').toBe(true);
}));
it('should not prevent the default enter action for a closed panel after a user action', () => {
@@ -1002,7 +1021,8 @@ describe('MDC-based MatAutocomplete', () => {
fixture.detectChanges();
fixture.componentInstance.trigger._handleKeydown(ENTER_EVENT);
- expect(ENTER_EVENT.defaultPrevented).toBe(false, 'Default action should not be prevented.');
+ expect(ENTER_EVENT.defaultPrevented)
+ .withContext('Default action should not be prevented.').toBe(false);
});
it('should fill the text field, not select an option, when SPACE is entered', () => {
@@ -1016,12 +1036,13 @@ describe('MDC-based MatAutocomplete', () => {
fixture.componentInstance.trigger._handleKeydown(SPACE_EVENT);
fixture.detectChanges();
- expect(input.value).not.toContain('New York', `Expected option not to be selected on SPACE.`);
+ expect(input.value).not
+ .withContext(`Expected option not to be selected on SPACE.`).toContain('New York');
});
it('should mark the control dirty when selecting an option from the keyboard', fakeAsync(() => {
expect(fixture.componentInstance.stateCtrl.dirty)
- .toBe(false, `Expected control to start out pristine.`);
+ .withContext(`Expected control to start out pristine.`).toBe(false);
fixture.componentInstance.trigger._handleKeydown(DOWN_ARROW_EVENT);
flush();
@@ -1029,7 +1050,8 @@ describe('MDC-based MatAutocomplete', () => {
fixture.detectChanges();
expect(fixture.componentInstance.stateCtrl.dirty)
- .toBe(true, `Expected control to become dirty when option was selected by ENTER.`);
+ .withContext(`Expected control to become dirty when option was selected by ENTER.`)
+ .toBe(true);
}));
it('should open the panel again when typing after making a selection', fakeAsync(() => {
@@ -1040,9 +1062,9 @@ describe('MDC-based MatAutocomplete', () => {
tick();
expect(fixture.componentInstance.trigger.panelOpen)
- .toBe(false, `Expected panel state to read closed after ENTER key.`);
+ .withContext(`Expected panel state to read closed after ENTER key.`).toBe(false);
expect(overlayContainerElement.textContent)
- .toEqual('', `Expected panel to close after ENTER key.`);
+ .withContext(`Expected panel to close after ENTER key.`).toEqual('');
dispatchFakeEvent(input, 'focusin');
clearElement(input);
@@ -1051,9 +1073,9 @@ describe('MDC-based MatAutocomplete', () => {
tick();
expect(fixture.componentInstance.trigger.panelOpen)
- .toBe(true, `Expected panel state to read open when typing in input.`);
+ .withContext(`Expected panel state to read open when typing in input.`).toBe(true);
expect(overlayContainerElement.textContent)
- .toContain('Alabama', `Expected panel to display when typing in input.`);
+ .withContext(`Expected panel to display when typing in input.`).toContain('Alabama');
}));
it('should not open the panel if the `input` event was dispatched with changing the value',
@@ -1065,12 +1087,14 @@ describe('MDC-based MatAutocomplete', () => {
fixture.detectChanges();
tick();
- expect(trigger.panelOpen).toBe(true, 'Expected panel to be open.');
+ expect(trigger.panelOpen)
+ .withContext('Expected panel to be open.').toBe(true);
trigger.closePanel();
fixture.detectChanges();
- expect(trigger.panelOpen).toBe(false, 'Expected panel to be closed.');
+ expect(trigger.panelOpen)
+ .withContext('Expected panel to be closed.').toBe(false);
// Dispatch the event without actually changing the value
// to simulate what happen in some cases on IE.
@@ -1078,7 +1102,8 @@ describe('MDC-based MatAutocomplete', () => {
fixture.detectChanges();
tick();
- expect(trigger.panelOpen).toBe(false, 'Expected panel to stay closed.');
+ expect(trigger.panelOpen)
+ .withContext('Expected panel to stay closed.').toBe(false);
}));
it('should scroll to active options below the fold', () => {
@@ -1088,14 +1113,16 @@ describe('MDC-based MatAutocomplete', () => {
trigger._handleKeydown(DOWN_ARROW_EVENT);
fixture.detectChanges();
- expect(scrollContainer.scrollTop).toEqual(0, `Expected panel not to scroll.`);
+ expect(scrollContainer.scrollTop)
+ .withContext(`Expected panel not to scroll.`).toEqual(0);
// These down arrows will set the 6th option active, below the fold.
[1, 2, 3, 4, 5].forEach(() => trigger._handleKeydown(DOWN_ARROW_EVENT));
// Expect option bottom minus the panel height plus padding (288 - 256 + 8 = 40)
- expect(scrollContainer.scrollTop)
- .toEqual(40, `Expected panel to reveal the sixth option.`);
+ // Expect option bottom minus the panel height plus padding (288 - 256 + 8 = 40)
+expect(scrollContainer.scrollTop)
+ .withContext(`Expected panel to reveal the sixth option.`).toEqual(40);
});
it('should scroll to active options below if the option height is variable', () => {
@@ -1113,14 +1140,16 @@ describe('MDC-based MatAutocomplete', () => {
trigger._handleKeydown(DOWN_ARROW_EVENT);
fixture.detectChanges();
- expect(scrollContainer.scrollTop).toEqual(0, `Expected panel not to scroll.`);
+ expect(scrollContainer.scrollTop)
+ .withContext(`Expected panel not to scroll.`).toEqual(0);
// These down arrows will set the 6th option active, below the fold.
[1, 2, 3, 4, 5].forEach(() => trigger._handleKeydown(DOWN_ARROW_EVENT));
// Expect option bottom minus the panel height (336 - 256 + 8 = 88)
- expect(scrollContainer.scrollTop)
- .toEqual(88, `Expected panel to reveal the sixth option.`);
+ // Expect option bottom minus the panel height (336 - 256 + 8 = 88)
+expect(scrollContainer.scrollTop)
+ .withContext(`Expected panel to reveal the sixth option.`).toEqual(88);
});
it('should scroll to active options on UP arrow', () => {
@@ -1132,7 +1161,7 @@ describe('MDC-based MatAutocomplete', () => {
fixture.detectChanges();
expect(scrollContainer.scrollTop)
- .toBeGreaterThan(initialScrollTop, `Expected panel to reveal last option.`);
+ .withContext(`Expected panel to reveal last option.`).toBeGreaterThan(initialScrollTop);
});
it('should not scroll to active options that are fully in the panel', () => {
@@ -1143,21 +1172,25 @@ describe('MDC-based MatAutocomplete', () => {
trigger._handleKeydown(DOWN_ARROW_EVENT);
fixture.detectChanges();
- expect(scrollContainer.scrollTop).toEqual(0, `Expected panel not to scroll.`);
+ expect(scrollContainer.scrollTop)
+ .withContext(`Expected panel not to scroll.`).toEqual(0);
// These down arrows will set the 6th option active, below the fold.
[1, 2, 3, 4, 5].forEach(() => trigger._handleKeydown(DOWN_ARROW_EVENT));
+ // Expect option bottom minus the panel height plus the padding (288 - 256 + 8 = 40)
// Expect option bottom minus the panel height plus the padding (288 - 256 + 8 = 40)
expect(scrollContainer.scrollTop)
- .toEqual(40, `Expected panel to reveal the sixth option.`);
+ .withContext(`Expected panel to reveal the sixth option.`).toEqual(40);
// These up arrows will set the 2nd option active
[4, 3, 2, 1].forEach(() => trigger._handleKeydown(UP_ARROW_EVENT));
+ // Expect no scrolling to have occurred. Still showing bottom of 6th option.
// Expect no scrolling to have occurred. Still showing bottom of 6th option.
expect(scrollContainer.scrollTop)
- .toEqual(40, `Expected panel not to scroll up since sixth option still fully visible.`);
+ .withContext(`Expected panel not to scroll up since sixth option still fully visible.`)
+ .toEqual(40);
});
it('should scroll to active options that are above the panel', () => {
@@ -1168,7 +1201,8 @@ describe('MDC-based MatAutocomplete', () => {
trigger._handleKeydown(DOWN_ARROW_EVENT);
fixture.detectChanges();
- expect(scrollContainer.scrollTop).toEqual(0, `Expected panel not to scroll.`);
+ expect(scrollContainer.scrollTop)
+ .withContext(`Expected panel not to scroll.`).toEqual(0);
// These down arrows will set the 7th option active, below the fold.
[1, 2, 3, 4, 5, 6].forEach(() => trigger._handleKeydown(DOWN_ARROW_EVENT));
@@ -1176,9 +1210,10 @@ describe('MDC-based MatAutocomplete', () => {
// These up arrows will set the 2nd option active
[5, 4, 3, 2, 1].forEach(() => trigger._handleKeydown(UP_ARROW_EVENT));
+ // Expect to show the top of the 2nd option at the top of the panel
// Expect to show the top of the 2nd option at the top of the panel
expect(scrollContainer.scrollTop)
- .toEqual(56, `Expected panel to scroll up when option is above panel.`);
+ .withContext(`Expected panel to scroll up when option is above panel.`).toEqual(56);
});
it('should close the panel when pressing escape', fakeAsync(() => {
@@ -1188,14 +1223,18 @@ describe('MDC-based MatAutocomplete', () => {
flush();
fixture.detectChanges();
- expect(document.activeElement).toBe(input, 'Expected input to be focused.');
- expect(trigger.panelOpen).toBe(true, 'Expected panel to be open.');
+ expect(document.activeElement)
+ .withContext('Expected input to be focused.').toBe(input);
+ expect(trigger.panelOpen)
+ .withContext('Expected panel to be open.').toBe(true);
dispatchKeyboardEvent(document.body, 'keydown', ESCAPE);
fixture.detectChanges();
- expect(document.activeElement).toBe(input, 'Expected input to continue to be focused.');
- expect(trigger.panelOpen).toBe(false, 'Expected panel to be closed.');
+ expect(document.activeElement)
+ .withContext('Expected input to continue to be focused.').toBe(input);
+ expect(trigger.panelOpen)
+ .withContext('Expected panel to be closed.').toBe(false);
}));
it('should prevent the default action when pressing escape', fakeAsync(() => {
@@ -1212,15 +1251,20 @@ describe('MDC-based MatAutocomplete', () => {
flush();
fixture.detectChanges();
- expect(document.activeElement).toBe(input, 'Expected input to be focused.');
- expect(trigger.panelOpen).toBe(true, 'Expected panel to be open.');
+ expect(document.activeElement)
+ .withContext('Expected input to be focused.').toBe(input);
+ expect(trigger.panelOpen)
+ .withContext('Expected panel to be open.').toBe(true);
const event = dispatchKeyboardEvent(document.body, 'keydown', ESCAPE, undefined, {alt: true});
fixture.detectChanges();
- expect(document.activeElement).toBe(input, 'Expected input to continue to be focused.');
- expect(trigger.panelOpen).toBe(true, 'Expected panel to stay open.');
- expect(event.defaultPrevented).toBe(false, 'Expected default action not to be prevented.');
+ expect(document.activeElement)
+ .withContext('Expected input to continue to be focused.').toBe(input);
+ expect(trigger.panelOpen)
+ .withContext('Expected panel to stay open.').toBe(true);
+ expect(event.defaultPrevented)
+ .withContext('Expected default action not to be prevented.').toBe(false);
}));
it('should close the panel when pressing ALT + UP_ARROW', fakeAsync(() => {
@@ -1232,14 +1276,18 @@ describe('MDC-based MatAutocomplete', () => {
flush();
fixture.detectChanges();
- expect(document.activeElement).toBe(input, 'Expected input to be focused.');
- expect(trigger.panelOpen).toBe(true, 'Expected panel to be open.');
+ expect(document.activeElement)
+ .withContext('Expected input to be focused.').toBe(input);
+ expect(trigger.panelOpen)
+ .withContext('Expected panel to be open.').toBe(true);
dispatchEvent(document.body, upArrowEvent);
fixture.detectChanges();
- expect(document.activeElement).toBe(input, 'Expected input to continue to be focused.');
- expect(trigger.panelOpen).toBe(false, 'Expected panel to be closed.');
+ expect(document.activeElement)
+ .withContext('Expected input to continue to be focused.').toBe(input);
+ expect(trigger.panelOpen)
+ .withContext('Expected panel to be closed.').toBe(false);
expect(upArrowEvent.stopPropagation).toHaveBeenCalled();
}));
@@ -1251,14 +1299,16 @@ describe('MDC-based MatAutocomplete', () => {
flush();
expect(overlayContainerElement.querySelector('.mat-mdc-autocomplete-panel'))
- .toBeTruthy('Expected panel to be rendered.');
+ .withContext('Expected panel to be rendered.')
+ .toBeTruthy();
dispatchKeyboardEvent(input, 'keydown', TAB);
fixture.detectChanges();
tick();
expect(overlayContainerElement.querySelector('.mat-mdc-autocomplete-panel'))
- .toBeFalsy('Expected panel to be removed.');
+ .withContext('Expected panel to be removed.')
+ .toBeFalsy();
}));
it('should reset the active option when closing with the escape key', fakeAsync(() => {
@@ -1268,8 +1318,10 @@ describe('MDC-based MatAutocomplete', () => {
fixture.detectChanges();
tick();
- expect(trigger.panelOpen).toBe(true, 'Expected panel to be open.');
- expect(!!trigger.activeOption).toBe(false, 'Expected no active option.');
+ expect(trigger.panelOpen)
+ .withContext('Expected panel to be open.').toBe(true);
+ expect(!!trigger.activeOption)
+ .withContext('Expected no active option.').toBe(false);
// Press the down arrow a few times.
[1, 2, 3].forEach(() => {
@@ -1280,12 +1332,16 @@ describe('MDC-based MatAutocomplete', () => {
// Note that this casts to a boolean, in order to prevent Jasmine
// from crashing when trying to stringify the option if the test fails.
- expect(!!trigger.activeOption).toBe(true, 'Expected to find an active option.');
+ // Note that this casts to a boolean, in order to prevent Jasmine
+ // from crashing when trying to stringify the option if the test fails.
+ expect(!!trigger.activeOption)
+ .withContext('Expected to find an active option.').toBe(true);
dispatchKeyboardEvent(document.body, 'keydown', ESCAPE);
tick();
- expect(!!trigger.activeOption).toBe(false, 'Expected no active options.');
+ expect(!!trigger.activeOption)
+ .withContext('Expected no active options.').toBe(false);
}));
it('should reset the active option when closing by selecting with enter', fakeAsync(() => {
@@ -1295,8 +1351,10 @@ describe('MDC-based MatAutocomplete', () => {
fixture.detectChanges();
tick();
- expect(trigger.panelOpen).toBe(true, 'Expected panel to be open.');
- expect(!!trigger.activeOption).toBe(false, 'Expected no active option.');
+ expect(trigger.panelOpen)
+ .withContext('Expected panel to be open.').toBe(true);
+ expect(!!trigger.activeOption)
+ .withContext('Expected no active option.').toBe(false);
// Press the down arrow a few times.
[1, 2, 3].forEach(() => {
@@ -1307,12 +1365,16 @@ describe('MDC-based MatAutocomplete', () => {
// Note that this casts to a boolean, in order to prevent Jasmine
// from crashing when trying to stringify the option if the test fails.
- expect(!!trigger.activeOption).toBe(true, 'Expected to find an active option.');
+ // Note that this casts to a boolean, in order to prevent Jasmine
+ // from crashing when trying to stringify the option if the test fails.
+ expect(!!trigger.activeOption)
+ .withContext('Expected to find an active option.').toBe(true);
trigger._handleKeydown(ENTER_EVENT);
tick();
- expect(!!trigger.activeOption).toBe(false, 'Expected no active options.');
+ expect(!!trigger.activeOption)
+ .withContext('Expected no active options.').toBe(false);
}));
});
@@ -1339,7 +1401,8 @@ describe('MDC-based MatAutocomplete', () => {
fixture.componentInstance.trigger._handleKeydown(DOWN_ARROW_EVENT);
tick();
fixture.detectChanges();
- expect(container.scrollTop).toBe(0, 'Expected the panel not to scroll.');
+ expect(container.scrollTop)
+ .withContext('Expected the panel not to scroll.').toBe(0);
// Press the down arrow five times.
[1, 2, 3, 4, 5].forEach(() => {
@@ -1347,10 +1410,12 @@ describe('MDC-based MatAutocomplete', () => {
tick();
});
+ //