|
| 1 | +import {expectAsyncError} from '@angular/cdk/private/testing'; |
1 | 2 | import {HarnessLoader} from '@angular/cdk/testing'; |
2 | 3 | import {TestbedHarnessEnvironment} from '@angular/cdk/testing/testbed'; |
3 | 4 | import {Component} from '@angular/core'; |
@@ -51,6 +52,26 @@ export function runHarnessTests( |
51 | 52 | expect(tabs.length).toBe(3); |
52 | 53 | }); |
53 | 54 |
|
| 55 | + it('should be able to get filtered tabs', async () => { |
| 56 | + const tabGroup = await loader.getHarness(tabGroupHarness); |
| 57 | + const tabs = await tabGroup.getTabs({label: 'Third'}); |
| 58 | + expect(tabs.length).toBe(1); |
| 59 | + expect(await tabs[0].getLabel()).toBe('Third'); |
| 60 | + }); |
| 61 | + |
| 62 | + it('should be able to select tab from tab-group', async () => { |
| 63 | + const tabGroup = await loader.getHarness(tabGroupHarness); |
| 64 | + expect(await (await tabGroup.getSelectedTab()).getLabel()).toBe('First'); |
| 65 | + await tabGroup.selectTab({label: 'Second'}); |
| 66 | + expect(await (await tabGroup.getSelectedTab()).getLabel()).toBe('Second'); |
| 67 | + }); |
| 68 | + |
| 69 | + it('should throw error when attempting to select invalid tab', async () => { |
| 70 | + const tabGroup = await loader.getHarness(tabGroupHarness); |
| 71 | + await expectAsyncError(() => tabGroup.selectTab({label: 'Fake'}), |
| 72 | + /Error: Cannot find mat-tab matching {"label":"Fake"}/); |
| 73 | + }); |
| 74 | + |
54 | 75 | it('should be able to get label of tabs', async () => { |
55 | 76 | const tabGroup = await loader.getHarness(tabGroupHarness); |
56 | 77 | const tabs = await tabGroup.getTabs(); |
@@ -78,13 +99,9 @@ export function runHarnessTests( |
78 | 99 | it('should be able to get content element of active tab', async () => { |
79 | 100 | const tabGroup = await loader.getHarness(tabGroupHarness); |
80 | 101 | const tabs = await tabGroup.getTabs(); |
81 | | - expect(await (await tabs[0].getContentElement()).text()).toBe('Content 1'); |
82 | | - }); |
83 | | - |
84 | | - it('should be able to get content element of active tab', async () => { |
85 | | - const tabGroup = await loader.getHarness(tabGroupHarness); |
86 | | - const tabs = await tabGroup.getTabs(); |
87 | | - expect(await (await tabs[0].getContentElement()).text()).toBe('Content 1'); |
| 102 | + const contentSelector = await tabs[0].getSelectorForContent(); |
| 103 | + const contentEl = document.querySelector(contentSelector) as HTMLElement; |
| 104 | + expect(contentEl.innerText.trim()).toBe('Content 1'); |
88 | 105 | }); |
89 | 106 |
|
90 | 107 | it('should be able to get disabled state of tab', async () => { |
|
0 commit comments