Skip to content

Instantly share code, notes, and snippets.

@cartant
Last active June 27, 2018 05:24
Show Gist options
  • Select an option

  • Save cartant/a0cfaf27521dd46e1586ac244f9959da to your computer and use it in GitHub Desktop.

Select an option

Save cartant/a0cfaf27521dd46e1586ac244f9959da to your computer and use it in GitHub Desktop.
import { TestBed, async } from '@angular/core/testing';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { fakeSchedulers } from 'rxjs-marbles/jasmine/angular';
import { SomeComponent } from './some.component';
describe("SomeComponent", () => {
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [SomeComponent],
imports: [FormsModule, ReactiveFormsModule]
}).compileComponents();
}));
it('should indicate when searching', fakeSchedulers(() => {
const fixture = TestBed.createComponent(SomeComponent);
fixture.detectChanges();
const compiled = fixture.debugElement.nativeElement;
const input = compiled.querySelector('input');
expect(compiled.querySelector('.searching')).toBeNull();
input.value = 'foo';
input.dispatchEvent(new Event('input', { bubbles: true }));
fixture.detectChanges();
expect(compiled.querySelector('.searching')).toBeNull();
tick(400);
fixture.detectChanges();
expect(compiled.querySelector('.searching')).not.toBeNull();
expect(compiled.querySelector('.searching span').textContent).toMatch(/foo/);
}));
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment