-
Notifications
You must be signed in to change notification settings - Fork 6.8k
/
Copy pathstepper-harness-example.spec.ts
60 lines (50 loc) · 1.94 KB
/
stepper-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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import {ComponentFixture, TestBed} from '@angular/core/testing';
import {TestbedHarnessEnvironment} from '@angular/cdk/testing/testbed';
import {MatStepperHarness, MatStepperNextHarness} from '@angular/material/stepper/testing';
import {HarnessLoader, parallel} from '@angular/cdk/testing';
import {StepperHarnessExample} from './stepper-harness-example';
describe('StepperHarnessExample', () => {
let fixture: ComponentFixture<StepperHarnessExample>;
let loader: HarnessLoader;
beforeEach(() => {
fixture = TestBed.createComponent(StepperHarnessExample);
fixture.detectChanges();
loader = TestbedHarnessEnvironment.loader(fixture);
});
it('should load all stepper harnesses', async () => {
const steppers = await loader.getAllHarnesses(MatStepperHarness);
expect(steppers.length).toBe(1);
});
it('should get the steps of a stepper', async () => {
const stepper = await loader.getHarness(MatStepperHarness);
const steps = await stepper.getSteps();
expect(steps.length).toEqual(3);
});
it('should be able to get the template-based label of a step', async () => {
const stepper = await loader.getHarness(MatStepperHarness);
const steps = await stepper.getSteps();
expect(
await parallel(() => {
return steps.map(step => step.getLabel());
}),
).toEqual(['One', 'Two', 'Three']);
});
it('should go forward when pressing the next button', async () => {
const stepper = await loader.getHarness(MatStepperHarness);
const steps = await stepper.getSteps();
const secondStep = steps[1];
const nextButton = await secondStep.getHarness(MatStepperNextHarness);
await secondStep.select();
expect(await parallel(() => steps.map(step => step.isSelected()))).toEqual([
false,
true,
false,
]);
await nextButton.click();
expect(await parallel(() => steps.map(step => step.isSelected()))).toEqual([
false,
false,
true,
]);
});
});