mirror of
https://github.com/angular/angular.git
synced 2026-09-14 13:54:52 +08:00
This commit is contained in:
committed by
Joey Perrott
parent
7caf12618e
commit
1bcd8ca12c
@@ -1,8 +1,7 @@
|
||||
import {Component, DebugElement} from '@angular/core';
|
||||
import {By} from '@angular/platform-browser';
|
||||
import {fakeAsync, ComponentFixture, TestBed} from '@angular/core/testing';
|
||||
import {async, ComponentFixture, TestBed} from '@angular/core/testing';
|
||||
import {MatChip, MatChipsModule} from './index';
|
||||
import {dispatchFakeEvent} from '@angular/cdk/testing';
|
||||
|
||||
describe('Chip Remove', () => {
|
||||
let fixture: ComponentFixture<any>;
|
||||
@@ -10,7 +9,7 @@ describe('Chip Remove', () => {
|
||||
let chipDebugElement: DebugElement;
|
||||
let chipNativeElement: HTMLElement;
|
||||
|
||||
beforeEach(fakeAsync(() => {
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [MatChipsModule],
|
||||
declarations: [
|
||||
@@ -19,6 +18,9 @@ describe('Chip Remove', () => {
|
||||
});
|
||||
|
||||
TestBed.compileComponents();
|
||||
}));
|
||||
|
||||
beforeEach(async(() => {
|
||||
fixture = TestBed.createComponent(TestChip);
|
||||
testChip = fixture.debugElement.componentInstance;
|
||||
fixture.detectChanges();
|
||||
@@ -28,14 +30,14 @@ describe('Chip Remove', () => {
|
||||
}));
|
||||
|
||||
describe('basic behavior', () => {
|
||||
it('should apply the `mat-chip-remove` CSS class', () => {
|
||||
const hrefElement = chipNativeElement.querySelector('a')!;
|
||||
it('should applies the `mat-chip-remove` CSS class', () => {
|
||||
let hrefElement = chipNativeElement.querySelector('a')!;
|
||||
|
||||
expect(hrefElement.classList).toContain('mat-chip-remove');
|
||||
});
|
||||
|
||||
it('should emit (remove) on click', () => {
|
||||
const hrefElement = chipNativeElement.querySelector('a')!;
|
||||
it('should emits (remove) on click', () => {
|
||||
let hrefElement = chipNativeElement.querySelector('a')!;
|
||||
|
||||
testChip.removable = true;
|
||||
fixture.detectChanges();
|
||||
@@ -46,19 +48,6 @@ describe('Chip Remove', () => {
|
||||
|
||||
expect(testChip.didRemove).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should prevent the default click action', () => {
|
||||
const hrefElement = chipNativeElement.querySelector('a')!;
|
||||
|
||||
testChip.removable = true;
|
||||
fixture.detectChanges();
|
||||
|
||||
const event = dispatchFakeEvent(hrefElement, 'click');
|
||||
fixture.detectChanges();
|
||||
|
||||
expect(event.defaultPrevented).toBe(true);
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -308,7 +308,7 @@ export class MatChip extends _MatChipMixinBase implements FocusableOption, OnDes
|
||||
selector: '[matChipRemove]',
|
||||
host: {
|
||||
'class': 'mat-chip-remove',
|
||||
'(click)': '_handleClick($event)',
|
||||
'(click)': '_handleClick()',
|
||||
}
|
||||
})
|
||||
export class MatChipRemove {
|
||||
@@ -316,14 +316,9 @@ export class MatChipRemove {
|
||||
}
|
||||
|
||||
/** Calls the parent chip's public `remove()` method if applicable. */
|
||||
_handleClick(event: MouseEvent): void {
|
||||
_handleClick(): void {
|
||||
if (this._parentChip.removable) {
|
||||
this._parentChip.remove();
|
||||
|
||||
// Note: the parent chip does something similar, however since we're removing it,
|
||||
// its event handler will be unbound before it has had the chance to fire.
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user