Skip to content

Commit 5b46ab0

Browse files
committed
Add tests for removal functionality
1 parent 070d68e commit 5b46ab0

File tree

2 files changed

+65
-6
lines changed

2 files changed

+65
-6
lines changed

src/material-experimental/mdc-chips/testing/chip-harness.spec.ts

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,12 @@ let loader: HarnessLoader;
1010

1111
describe('MatChipHarness', () => {
1212
beforeEach(async () => {
13-
await TestBed.configureTestingModule({
14-
imports: [MatChipsModule],
15-
declarations: [ChipHarnessTest],
16-
}).compileComponents();
13+
await TestBed
14+
.configureTestingModule({
15+
imports: [MatChipsModule],
16+
declarations: [ChipHarnessTest],
17+
})
18+
.compileComponents();
1719

1820
fixture = TestBed.createComponent(ChipHarnessTest);
1921
fixture.detectChanges();
@@ -32,6 +34,25 @@ describe('MatChipHarness', () => {
3234
expect(await harnesses[2].getText()).toBe('Chip with avatar');
3335
expect(await harnesses[3].getText()).toBe('Disabled Chip');
3436
});
37+
38+
it('correctly identifies chips without matChipRemove elements as irremovable', async () => {
39+
const harnesses = await loader.getAllHarnesses(MatChipHarness);
40+
41+
expect(await harnesses[0].isRemovable()).toBeTrue();
42+
});
43+
44+
it('correctly identifies chips with matChipRemove elements as removable', async () => {
45+
const harnesses = await loader.getAllHarnesses(MatChipHarness);
46+
47+
expect(await harnesses[3].isRemovable()).toBeTrue();
48+
});
49+
50+
it('should be able to remove a chip', async () => {
51+
const harnesses = await loader.getAllHarnesses(MatChipHarness);
52+
await harnesses[3].remove();
53+
54+
expect(harnesses.length).toBe(3);
55+
});
3556
});
3657

3758
@Component({
@@ -42,5 +63,5 @@ describe('MatChipHarness', () => {
4263
<mat-chip disabled>Disabled Chip <span matChipRemove>remove_icon</span></mat-chip>
4364
`
4465
})
45-
class ChipHarnessTest {}
46-
66+
class ChipHarnessTest {
67+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import {HarnessLoader} from '@angular/cdk/testing';
2+
import {TestbedHarnessEnvironment} from '@angular/cdk/testing/testbed';
3+
import {Component} from '@angular/core';
4+
import {ComponentFixture, TestBed} from '@angular/core/testing';
5+
import {MatChipsModule} from '../index';
6+
import {MatChipRemoveHarness} from './chip-remove-harness';
7+
8+
let fixture: ComponentFixture<ChipRemoveHarnessTest>;
9+
let loader: HarnessLoader;
10+
11+
describe('MatChipRemoveHarness', () => {
12+
beforeEach(async () => {
13+
await TestBed
14+
.configureTestingModule({
15+
imports: [MatChipsModule],
16+
declarations: [ChipRemoveHarnessTest],
17+
})
18+
.compileComponents();
19+
20+
fixture = TestBed.createComponent(ChipRemoveHarnessTest);
21+
fixture.detectChanges();
22+
loader = TestbedHarnessEnvironment.loader(fixture);
23+
});
24+
25+
it('should get correct number of chip remove harnesses', async () => {
26+
const harnesses = await loader.getAllHarnesses(MatChipRemoveHarness);
27+
expect(harnesses.length).toBe(1);
28+
});
29+
});
30+
31+
@Component({
32+
template: `
33+
<mat-basic-chip>Basic Chip w/ Remove <span matChipRemove>remove_icon</span></mat-basic-chip>
34+
<mat-chip>Chip w/o Remove</mat-chip>
35+
`
36+
})
37+
class ChipRemoveHarnessTest {
38+
}

0 commit comments

Comments
 (0)