-
Notifications
You must be signed in to change notification settings - Fork 6.8k
/
Copy pathselect-harness-example.spec.ts
53 lines (41 loc) · 1.78 KB
/
select-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
import {ComponentFixture, TestBed} from '@angular/core/testing';
import {TestbedHarnessEnvironment} from '@angular/cdk/testing/testbed';
import {MatSelectHarness} from '@angular/material/select/testing';
import {MATERIAL_ANIMATIONS} from '@angular/material/core';
import {HarnessLoader} from '@angular/cdk/testing';
import {SelectHarnessExample} from './select-harness-example';
describe('SelectHarnessExample', () => {
let fixture: ComponentFixture<SelectHarnessExample>;
let loader: HarnessLoader;
beforeEach(() => {
TestBed.configureTestingModule({
providers: [{provide: MATERIAL_ANIMATIONS, useValue: {animationsDisabled: true}}],
});
fixture = TestBed.createComponent(SelectHarnessExample);
fixture.detectChanges();
loader = TestbedHarnessEnvironment.loader(fixture);
});
it('should load all select harnesses', async () => {
const selects = await loader.getAllHarnesses(MatSelectHarness);
expect(selects.length).toBe(1);
});
it('should be able to check whether a select is in multi-selection mode', async () => {
const select = await loader.getHarness(MatSelectHarness);
expect(await select.isMultiple()).toBe(false);
});
it('should be able to open and close a select', async () => {
const select = await loader.getHarness(MatSelectHarness);
expect(await select.isOpen()).toBe(false);
await select.open();
expect(await select.isOpen()).toBe(true);
await select.close();
expect(await select.isOpen()).toBe(false);
});
it('should be able to get the value text from a select', async () => {
const select = await loader.getHarness(MatSelectHarness);
await select.open();
const options = await select.getOptions();
await options[2].click();
expect(await select.getValueText()).toBe('Tacos');
});
});