Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import {async, ComponentFixture, fakeAsync, TestBed} from '@angular/core/testing';
- import { WeatherComponent } from './weather.component';
- import {WeatherService} from './weather.service';
- import {Weather} from '../shared/models/weather';
- import {Observable, of, Subject} from 'rxjs';
- class WeatherServiceStub {
- public weatherChanged: Subject<Weather[]> = new Subject<Weather[]>();
- }
- describe('WeatherComponent', () => {
- let component: WeatherComponent;
- let fixture: ComponentFixture<WeatherComponent>;
- let weatherService: WeatherService;
- beforeEach(async(() => {
- TestBed.configureTestingModule({
- declarations: [ WeatherComponent ],
- providers: [
- {provide: WeatherService, useClass: WeatherServiceStub}
- ]
- })
- .compileComponents();
- }));
- beforeEach(() => {
- fixture = TestBed.createComponent(WeatherComponent);
- component = fixture.componentInstance;
- weatherService = TestBed.get(WeatherService);
- fixture.detectChanges();
- });
- it('should create', () => {
- expect(component).toBeTruthy();
- });
- fit('should do something with weather array', fakeAsync(() => {
- console.log(component.weather);
- fixture.detectChanges();
- // weatherService.weatherChanged is subject, how is it works?!?!?!
- spyOn(weatherService, 'weatherChanged').and.returnValues(
- of([{id: 1, name: 'heheszki'}]),
- of([{id: 1, name: 'heheszki'}, {id: 1, name: 'heheszki'}])
- );
- fixture.detectChanges();
- component.ngOnInit();
- fixture.detectChanges();
- console.log(component.weather);
- component.ngOnInit();
- console.log(component.weather);
- }));
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement