add unit tests
This commit is contained in:
32
src/app/modules/songs/services/song-list.resolver.spec.ts
Normal file
32
src/app/modules/songs/services/song-list.resolver.spec.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
import {TestBed} from '@angular/core/testing';
|
||||
import {of} from 'rxjs';
|
||||
import {SongService} from './song.service';
|
||||
import {SongListResolver} from './song-list.resolver';
|
||||
|
||||
describe('SongListResolver', () => {
|
||||
let resolver: SongListResolver;
|
||||
let songServiceSpy: jasmine.SpyObj<SongService>;
|
||||
|
||||
beforeEach(() => {
|
||||
songServiceSpy = jasmine.createSpyObj<SongService>('SongService', ['list$']);
|
||||
songServiceSpy.list$.and.returnValue(of([{id: 'song-1', title: 'Amazing Grace'}] as never));
|
||||
|
||||
void TestBed.configureTestingModule({
|
||||
providers: [{provide: SongService, useValue: songServiceSpy}],
|
||||
});
|
||||
|
||||
resolver = TestBed.inject(SongListResolver);
|
||||
});
|
||||
|
||||
it('should be created', () => {
|
||||
expect(resolver).toBeTruthy();
|
||||
});
|
||||
|
||||
it('should resolve the first emitted song list from the service', done => {
|
||||
resolver.resolve().subscribe(songs => {
|
||||
expect(songServiceSpy.list$).toHaveBeenCalled();
|
||||
expect(songs).toEqual([{id: 'song-1', title: 'Amazing Grace'}] as never);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user