-
Notifications
You must be signed in to change notification settings - Fork 6.8k
/
Copy pathexpansion-harness-example.spec.ts
45 lines (38 loc) · 1.77 KB
/
expansion-harness-example.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import {ComponentFixture, TestBed} from '@angular/core/testing';
import {TestbedHarnessEnvironment} from '@angular/cdk/testing/testbed';
import {MatAccordionHarness, MatExpansionPanelHarness} from '@angular/material/expansion/testing';
import {HarnessLoader} from '@angular/cdk/testing';
import {ExpansionHarnessExample} from './expansion-harness-example';
describe('ExpansionHarnessExample', () => {
let fixture: ComponentFixture<ExpansionHarnessExample>;
let loader: HarnessLoader;
beforeEach(() => {
fixture = TestBed.createComponent(ExpansionHarnessExample);
fixture.detectChanges();
loader = TestbedHarnessEnvironment.loader(fixture);
});
it('should be able to load accordion', async () => {
const accordions = await loader.getAllHarnesses(MatAccordionHarness);
expect(accordions.length).toBe(1);
});
it('should be able to load expansion panels', async () => {
const panels = await loader.getAllHarnesses(MatExpansionPanelHarness);
expect(panels.length).toBe(1);
});
it('should be able to toggle expansion state of panel', async () => {
const panel = await loader.getHarness(MatExpansionPanelHarness);
expect(await panel.isExpanded()).toBe(false);
await panel.toggle();
expect(await panel.isExpanded()).toBe(true);
});
it('should be able to get text content of expansion panel', async () => {
const panel = await loader.getHarness(MatExpansionPanelHarness);
expect(await panel.getTextContent()).toBe('I am the content!');
});
it('should be able to get expansion panels of accordion', async () => {
const accordion = await loader.getHarness(MatAccordionHarness);
const panels = await accordion.getExpansionPanels();
expect(panels.length).toBe(1);
expect(await panels[0].getTitle()).toBe('Welcome');
});
});