Skip to content

Commit 56e7c8f

Browse files
committed
Update tests
1 parent cd4deed commit 56e7c8f

File tree

1 file changed

+33
-19
lines changed

1 file changed

+33
-19
lines changed

src/lib/button/button.spec.ts

Lines changed: 33 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import {async, ComponentFixture, TestBed} from '@angular/core/testing';
2-
import {Component} from '@angular/core';
2+
import {Component, DebugElement} from '@angular/core';
33
import {By} from '@angular/platform-browser';
44
import {MdButtonModule} from './index';
55
import {ViewportRuler} from '../core/overlay/position/viewport-ruler';
66
import {FakeViewportRuler} from '../core/overlay/position/fake-viewport-ruler';
7+
import {MdRipple} from '../core/ripple/index';
78

89

910
describe('MdButton', () => {
@@ -156,41 +157,54 @@ describe('MdButton', () => {
156157
describe('button ripples', () => {
157158
let fixture: ComponentFixture<TestApp>;
158159
let testComponent: TestApp;
159-
let buttonElement: HTMLButtonElement;
160-
let anchorElement: HTMLAnchorElement;
160+
let buttonDebugElement: DebugElement;
161+
let buttonRippleDebugElement: DebugElement;
162+
let buttonRippleInstance: MdRipple;
163+
let anchorDebugElement: DebugElement;
164+
let anchorRippleDebugElement: DebugElement;
165+
let anchorRippleInstance: MdRipple;
161166

162167
beforeEach(() => {
163168
fixture = TestBed.createComponent(TestApp);
164169
fixture.detectChanges();
165170

166171
testComponent = fixture.componentInstance;
167-
buttonElement = fixture.nativeElement.querySelector('button[md-button]');
168-
anchorElement = fixture.nativeElement.querySelector('a[md-button]');
172+
173+
buttonDebugElement = fixture.debugElement.query(By.css('button[md-button]'));
174+
buttonRippleDebugElement = buttonDebugElement.query(By.directive(MdRipple));
175+
buttonRippleInstance = buttonRippleDebugElement.injector.get<MdRipple>(MdRipple);
176+
177+
anchorDebugElement = fixture.debugElement.query(By.css('a[md-button]'));
178+
anchorRippleDebugElement = anchorDebugElement.query(By.directive(MdRipple));
179+
anchorRippleInstance = anchorRippleDebugElement.injector.get<MdRipple>(MdRipple);
169180
});
170181

171-
it('should remove ripple if mdRippleDisabled input is set', () => {
172-
expect(buttonElement.querySelectorAll('[md-ripple]').length).toBe(1);
182+
it('should disable the ripple if mdRippleDisabled input is set', () => {
183+
expect(buttonRippleInstance.disabled).toBeFalsy();
173184

174185
testComponent.rippleDisabled = true;
175186
fixture.detectChanges();
176-
expect(buttonElement.querySelectorAll('[md-ripple]').length).toBe(0);
177-
});
178187

179-
it('should not have a ripple when the button is disabled', () => {
180-
let buttonRipple = buttonElement.querySelector('[md-ripple]');
181-
let anchorRipple = anchorElement.querySelector('[md-ripple]');
188+
expect(buttonRippleInstance.disabled).toBeTruthy();
189+
});
182190

183-
expect(buttonRipple).toBeTruthy('Expected an enabled button[md-button] to have a ripple');
184-
expect(anchorRipple).toBeTruthy('Expected an enabled a[md-button] to have a ripple');
191+
it('should disable the ripple when the button is disabled', () => {
192+
expect(buttonRippleInstance.disabled).toBeFalsy(
193+
'Expected an enabled button[md-button] to have an enabled ripple'
194+
);
195+
expect(anchorRippleInstance.disabled).toBeFalsy(
196+
'Expected an enabled a[md-button] to have an enabled ripple'
197+
);
185198

186199
testComponent.isDisabled = true;
187200
fixture.detectChanges();
188201

189-
buttonRipple = buttonElement.querySelector('button [md-ripple]');
190-
anchorRipple = anchorElement.querySelector('a [md-ripple]');
191-
192-
expect(buttonRipple).toBeFalsy('Expected a disabled button[md-button] not to have a ripple');
193-
expect(anchorRipple).toBeFalsy('Expected a disabled a[md-button] not to have a ripple');
202+
expect(buttonRippleInstance.disabled).toBeTruthy(
203+
'Expected a disabled button[md-button] not to have an enabled ripple'
204+
);
205+
expect(anchorRippleInstance.disabled).toBeTruthy(
206+
'Expected a disabled a[md-button] not to have an enabled ripple'
207+
);
194208
});
195209
});
196210
});

0 commit comments

Comments
 (0)