Skip to content

Commit 2695a61

Browse files
crisbetoandrewseguin
authored andcommitted
test(multiple): switch to non-deprecated test assertion context API
Passing in a context as the last parameter of the various test assertion functions is deprecated. These changes switch all of the tests to the new `.withContext` helper.
1 parent 30b79c0 commit 2695a61

File tree

109 files changed

+4399
-2994
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

109 files changed

+4399
-2994
lines changed

src/cdk-experimental/dialog/dialog.spec.ts

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -209,8 +209,8 @@ describe('Dialog', () => {
209209

210210
// beforeClose should emit before dialog container is destroyed
211211
const beforeCloseHandler = jasmine.createSpy('beforeClose callback').and.callFake(() => {
212-
expect(overlayContainerElement.querySelector('cdk-dialog-container'))
213-
.not.toBeNull('dialog container exists when beforeClose is called');
212+
expect(overlayContainerElement.querySelector('cdk-dialog-container')).not
213+
.withContext('dialog container exists when beforeClose is called').toBeNull();
214214
});
215215

216216
dialogRef.beforeClosed().subscribe(beforeCloseHandler);
@@ -261,15 +261,15 @@ describe('Dialog', () => {
261261
flushMicrotasks();
262262

263263
expect(overlayContainerElement.querySelectorAll('cdk-dialog-container').length)
264-
.toBe(1, 'Expected one open dialog.');
264+
.withContext('Expected one open dialog.').toBe(1);
265265

266266
dialogRef.close();
267267
flushMicrotasks();
268268
onPushFixture.detectChanges();
269269
tick(500);
270270

271271
expect(overlayContainerElement.querySelectorAll('cdk-dialog-container').length)
272-
.toBe(0, 'Expected no open dialogs.');
272+
.withContext('Expected no open dialogs.').toBe(0);
273273
}));
274274

275275
it('should close when clicking on the overlay backdrop', fakeAsync(() => {
@@ -403,8 +403,8 @@ describe('Dialog', () => {
403403

404404
let overlayPane = overlayContainerElement.querySelector('.cdk-overlay-pane') as HTMLElement;
405405

406-
expect(overlayPane.style.maxWidth).toBe('80vw',
407-
'Expected dialog to set a default max-width on overlay pane');
406+
expect(overlayPane.style.maxWidth)
407+
.withContext('Expected dialog to set a default max-width on overlay pane').toBe('80vw');
408408

409409
dialogRef.close();
410410

@@ -716,7 +716,8 @@ describe('Dialog', () => {
716716
viewContainerFixture.detectChanges();
717717
flush();
718718

719-
expect(dialogRef.componentInstance).toBeFalsy('Expected reference to have been cleared.');
719+
expect(dialogRef.componentInstance)
720+
.withContext('Expected reference to have been cleared.').toBeFalsy();
720721
}));
721722

722723
it('should assign a unique id to each dialog', () => {
@@ -891,7 +892,8 @@ describe('Dialog', () => {
891892
flushMicrotasks();
892893

893894
expect(document.activeElement!.tagName)
894-
.toBe('INPUT', 'Expected first tabbable element (input) in the dialog to be focused.');
895+
.withContext('Expected first tabbable element (input) in the dialog to be focused.')
896+
.toBe('INPUT');
895897
}));
896898

897899
it('should allow disabling focus of the first tabbable element', fakeAsync(() => {
@@ -931,8 +933,9 @@ describe('Dialog', () => {
931933
viewContainerFixture.detectChanges();
932934
flush();
933935

934-
expect(document.activeElement!.id).toBe('dialog-trigger',
935-
'Expected that the trigger was refocused after the dialog is closed.');
936+
expect(document.activeElement!.id)
937+
.withContext('Expected that the trigger was refocused after the dialog is closed.')
938+
.toBe('dialog-trigger');
936939

937940
document.body.removeChild(button);
938941
}));
@@ -990,14 +993,14 @@ describe('Dialog', () => {
990993
otherButton.focus();
991994

992995
expect(document.activeElement!.id)
993-
.toBe('other-button', 'Expected focus to be on the alternate button.');
996+
.withContext('Expected focus to be on the alternate button.').toBe('other-button');
994997

995998
flushMicrotasks();
996999
viewContainerFixture.detectChanges();
9971000
flush();
9981001

9991002
expect(document.activeElement!.id)
1000-
.toBe('other-button', 'Expected focus to stay on the alternate button.');
1003+
.withContext('Expected focus to stay on the alternate button.').toBe('other-button');
10011004

10021005
body.removeChild(button);
10031006
body.removeChild(otherButton);
@@ -1028,8 +1031,9 @@ describe('Dialog', () => {
10281031
viewContainerFixture.detectChanges();
10291032
flushMicrotasks();
10301033

1031-
expect(document.activeElement!.id).toBe('input-to-be-focused',
1032-
'Expected that the trigger was refocused after the dialog is closed.');
1034+
expect(document.activeElement!.id)
1035+
.withContext('Expected that the trigger was refocused after the dialog is closed.')
1036+
.toBe('input-to-be-focused');
10331037

10341038
document.body.removeChild(button);
10351039
document.body.removeChild(input);
@@ -1044,7 +1048,7 @@ describe('Dialog', () => {
10441048
flushMicrotasks();
10451049

10461050
expect(document.activeElement!.tagName.toLowerCase())
1047-
.toBe('cdk-dialog-container', 'Expected dialog container to be focused.');
1051+
.withContext('Expected dialog container to be focused.').toBe('cdk-dialog-container');
10481052
}));
10491053

10501054
});
@@ -1117,14 +1121,14 @@ describe('Dialog with a parent Dialog', () => {
11171121
flush();
11181122

11191123
expect(overlayContainerElement.textContent)
1120-
.toContain('Pizza', 'Expected a dialog to be opened');
1124+
.withContext('Expected a dialog to be opened').toContain('Pizza');
11211125

11221126
childDialog.closeAll();
11231127
fixture.detectChanges();
11241128
flush();
11251129

11261130
expect(overlayContainerElement.textContent!.trim())
1127-
.toBe('', 'Expected closeAll on child Dialog to close dialog opened by parent');
1131+
.withContext('Expected closeAll on child Dialog to close dialog opened by parent').toBe('');
11281132
}));
11291133

11301134
it('should close dialogs opened by a child when calling closeAll on a parent Dialog',
@@ -1133,14 +1137,14 @@ describe('Dialog with a parent Dialog', () => {
11331137
fixture.detectChanges();
11341138

11351139
expect(overlayContainerElement.textContent)
1136-
.toContain('Pizza', 'Expected a dialog to be opened');
1140+
.withContext('Expected a dialog to be opened').toContain('Pizza');
11371141

11381142
parentDialog.closeAll();
11391143
fixture.detectChanges();
11401144
flush();
11411145

11421146
expect(overlayContainerElement.textContent!.trim())
1143-
.toBe('', 'Expected closeAll on parent Dialog to close dialog opened by child');
1147+
.withContext('Expected closeAll on parent Dialog to close dialog opened by child').toBe('');
11441148
}));
11451149

11461150
it('should not close the parent dialogs, when a child is destroyed', fakeAsync(() => {
@@ -1149,14 +1153,14 @@ describe('Dialog with a parent Dialog', () => {
11491153
flush();
11501154

11511155
expect(overlayContainerElement.textContent)
1152-
.toContain('Pizza', 'Expected a dialog to be opened');
1156+
.withContext('Expected a dialog to be opened').toContain('Pizza');
11531157

11541158
childDialog.ngOnDestroy();
11551159
fixture.detectChanges();
11561160
flush();
11571161

11581162
expect(overlayContainerElement.textContent)
1159-
.toContain('Pizza', 'Expected a dialog to remain opened');
1163+
.withContext('Expected a dialog to remain opened').toContain('Pizza');
11601164
}));
11611165

11621166
it('should close the top dialog via the escape key', fakeAsync(() => {

src/cdk-experimental/listbox/listbox.spec.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -620,23 +620,23 @@ describe('CdkOption and CdkListbox', () => {
620620

621621
it('should be able to set the disabled state via setDisabledState', () => {
622622
expect(listboxInstance.disabled)
623-
.toBe(false, 'Expected the selection list to be enabled.');
623+
.withContext('Expected the selection list to be enabled.').toBe(false);
624624
expect(optionInstances.every(option => !option.disabled))
625-
.toBe(true, 'Expected every list option to be enabled.');
625+
.withContext('Expected every list option to be enabled.').toBe(true);
626626

627627
listboxInstance.setDisabledState(true);
628628
fixture.detectChanges();
629629

630630
expect(listboxInstance.disabled)
631-
.toBe(true, 'Expected the selection list to be disabled.');
631+
.withContext('Expected the selection list to be disabled.').toBe(true);
632632
for (const option of optionElements) {
633633
expect(option.getAttribute('aria-disabled')).toBe('true');
634634
}
635635
});
636636

637637
it('should be able to select options via writeValue', () => {
638638
expect(optionInstances.every(option => !option.disabled))
639-
.toBe(true, 'Expected every list option to be enabled.');
639+
.withContext('Expected every list option to be enabled.').toBe(true);
640640

641641
listboxInstance.writeValue('arc');
642642
fixture.detectChanges();
@@ -651,7 +651,7 @@ describe('CdkOption and CdkListbox', () => {
651651

652652
it('should be select multiple options by their values', () => {
653653
expect(optionInstances.every(option => !option.disabled))
654-
.toBe(true, 'Expected every list option to be enabled.');
654+
.withContext('Expected every list option to be enabled.').toBe(true);
655655

656656
testComponent.isMultiselectable = true;
657657
fixture.detectChanges();
@@ -676,7 +676,7 @@ describe('CdkOption and CdkListbox', () => {
676676
it('should be able to disable options from the control', () => {
677677
expect(testComponent.listbox.disabled).toBeFalse();
678678
expect(optionInstances.every(option => !option.disabled))
679-
.toBe(true, 'Expected every list option to be enabled.');
679+
.withContext('Expected every list option to be enabled.').toBe(true);
680680

681681
testComponent.form.disable();
682682
fixture.detectChanges();
@@ -690,7 +690,7 @@ describe('CdkOption and CdkListbox', () => {
690690
it('should be able to toggle disabled state after form control is disabled', () => {
691691
expect(testComponent.listbox.disabled).toBeFalse();
692692
expect(optionInstances.every(option => !option.disabled))
693-
.toBe(true, 'Expected every list option to be enabled.');
693+
.withContext('Expected every list option to be enabled.').toBe(true);
694694

695695
testComponent.form.disable();
696696
fixture.detectChanges();
@@ -705,7 +705,7 @@ describe('CdkOption and CdkListbox', () => {
705705

706706
expect(testComponent.listbox.disabled).toBeFalse();
707707
expect(optionInstances.every(option => !option.disabled))
708-
.toBe(true, 'Expected every list option to be enabled.');
708+
.withContext('Expected every list option to be enabled.').toBe(true);
709709
});
710710

711711
it('should be able to select options via setting the value in form control', () => {

src/cdk-experimental/scrolling/virtual-scroll-viewport.spec.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ describe('CdkVirtualScrollViewport', () => {
2929
const contentWrapper =
3030
viewport.elementRef.nativeElement.querySelector('.cdk-virtual-scroll-content-wrapper')!;
3131
expect(contentWrapper.children.length)
32-
.toBe(4, 'should render 4 50px items to fill 200px space');
32+
.withContext('should render 4 50px items to fill 200px space').toBe(4);
3333
}));
3434

3535
it('should render extra content if first item is smaller than average', fakeAsync(() => {
@@ -38,8 +38,9 @@ describe('CdkVirtualScrollViewport', () => {
3838

3939
const contentWrapper =
4040
viewport.elementRef.nativeElement.querySelector('.cdk-virtual-scroll-content-wrapper')!;
41-
expect(contentWrapper.children.length).toBe(4,
42-
'should render 4 items to fill 200px space based on 50px estimate from first item');
41+
expect(contentWrapper.children.length)
42+
.withContext('should render 4 items to fill 200px space based on 50px ' +
43+
'estimate from first item').toBe(4);
4344
}));
4445

4546
it('should throw if maxBufferPx is less than minBufferPx', fakeAsync(() => {

src/cdk/a11y/aria-describer/aria-describer.spec.ts

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -128,38 +128,44 @@ describe('AriaDescriber', () => {
128128
const descriptionNode = fixture.nativeElement.querySelector('#description-with-existing-id');
129129

130130
expect(document.body.contains(descriptionNode))
131-
.toBe(true, 'Expected node to be inside the document to begin with.');
132-
expect(getMessagesContainer()).toBeNull('Expected no messages container on init.');
131+
.withContext('Expected node to be inside the document to begin with.')
132+
.toBe(true);
133+
expect(getMessagesContainer())
134+
.withContext('Expected no messages container on init.').toBeNull();
133135

134136
ariaDescriber.describe(component.element1, descriptionNode);
135137

136138
expectMessage(component.element1, 'Hello');
137139
expect(getMessagesContainer())
138-
.toBeNull('Expected no messages container after the element was described.');
140+
.withContext('Expected no messages container after the element was described.')
141+
.toBeNull();
139142

140143
ariaDescriber.removeDescription(component.element1, descriptionNode);
141144

142-
expect(document.body.contains(descriptionNode)).toBe(true,
143-
'Expected description node to still be in the DOM after it is no longer being used.');
145+
expect(document.body.contains(descriptionNode))
146+
.withContext('Expected description node to still be in the DOM after it is' +
147+
'no longer being used.').toBe(true);
144148
});
145149

146150
it('should keep nodes set as descriptions inside their original position in the DOM', () => {
147151
createFixture();
148152
const descriptionNode = fixture.nativeElement.querySelector('#description-with-existing-id');
149153
const initialParent = descriptionNode.parentNode;
150154

151-
expect(initialParent).toBeTruthy('Expected node to have a parent initially.');
155+
expect(initialParent).withContext('Expected node to have a parent initially.').toBeTruthy();
152156

153157
ariaDescriber.describe(component.element1, descriptionNode);
154158

155159
expectMessage(component.element1, 'Hello');
156-
expect(descriptionNode.parentNode).toBe(initialParent,
157-
'Expected node to stay inside the same parent when used as a description.');
160+
expect(descriptionNode.parentNode)
161+
.withContext('Expected node to stay inside the same parent when used as a description.')
162+
.toBe(initialParent);
158163

159164
ariaDescriber.removeDescription(component.element1, descriptionNode);
160165

161-
expect(descriptionNode.parentNode).toBe(initialParent,
162-
'Expected node to stay inside the same parent after not being used as a description.');
166+
expect(descriptionNode.parentNode)
167+
.withContext('Expected node to stay inside the same parent after not ' +
168+
'being used as a description.').toBe(initialParent);
163169
});
164170

165171
it('should be able to unregister messages while having others registered', () => {
@@ -247,7 +253,8 @@ describe('AriaDescriber', () => {
247253
const descriptionNode = fixture.nativeElement.querySelector('#description-with-existing-id');
248254

249255
expect(document.body.contains(descriptionNode))
250-
.toBe(true, 'Expected node to be inside the document to begin with.');
256+
.withContext('Expected node to be inside the document to begin with.')
257+
.toBe(true);
251258

252259
ariaDescriber.describe(component.element1, descriptionNode);
253260

@@ -257,8 +264,9 @@ describe('AriaDescriber', () => {
257264
ariaDescriber.ngOnDestroy();
258265

259266
expect(component.element1.hasAttribute(CDK_DESCRIBEDBY_HOST_ATTRIBUTE)).toBe(false);
260-
expect(document.body.contains(descriptionNode)).toBe(true,
261-
'Expected description node to still be in the DOM after it is no longer being used.');
267+
expect(document.body.contains(descriptionNode))
268+
.withContext('Expected description node to still be in the DOM after ' +
269+
'it is no longer being used.').toBe(true);
262270
});
263271

264272
it('should remove the aria-describedby attribute if there are no more messages', () => {

0 commit comments

Comments
 (0)