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
| import { QuoteService } from './quote.service'; import { QuoteComponent } from './quote.component'; import { provide } from '@angular/core'; import { async, TestBed, fakeAsync, tick, } from '@angular/core/testing';
class MockQuoteService { public quote: string = 'Test quote';
getQuote() { return Promise.resolve(this.quote); } }
describe('Testing Quote Component', () => {
let fixture;
beforeEach(() => { TestBed.configureTestingModule({ declarations: [ QuoteComponent ], providers: [ { provide: QuoteService, useClass: MockQuoteService } ] }); fixture = TestBed.createComponent(QuoteComponent); fixture.detectChanges(); });
it('Should get quote', fakeAsync(() => { fixture.componentInstance.getQuote(); tick(); fixture.detectChanges(); const compiled = fixture.debugElement.nativeElement; expect(compiled.querySelector('div').innerText).toEqual('Test quote'); })); });
|