-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🟢 Update tests to have code coverage in all green on all metrics, 97%+
98.86% Statements 87/88 100% Branches 13/13 97.14% Functions 34/35 98.83% Lines 85/86
- Loading branch information
1 parent
b496849
commit 5d382fd
Showing
3 changed files
with
62 additions
and
11 deletions.
There are no files selected for viewing
25 changes: 23 additions & 2 deletions
25
.../shared/data/rest/chuck-norris-joke-generator/chuck-norris-joke-generator.service.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,40 @@ | ||
import { TestBed } from '@angular/core/testing'; | ||
|
||
import { ChuckNorrisJokeGeneratorService } from './chuck-norris-joke-generator.service'; | ||
import { provideHttpClient } from '@angular/common/http'; | ||
import { HttpClient, provideHttpClient } from '@angular/common/http'; | ||
import { of } from 'rxjs'; | ||
import { ChuckNorrisJoke } from './chuck-norris-joke-generator.model'; | ||
|
||
describe('ChuckNorrisJokeGeneratorService', () => { | ||
let service: ChuckNorrisJokeGeneratorService; | ||
|
||
let httpClient: jasmine.SpyObj<HttpClient>; | ||
|
||
beforeEach(() => { | ||
let httpClient = jasmine.createSpyObj('HttpClient', ['get']); | ||
httpClient.get.and.returnValue( | ||
of({ value: 'God prays to Chuck Norris' } as ChuckNorrisJoke) | ||
); | ||
|
||
TestBed.configureTestingModule({ | ||
providers: [provideHttpClient()], | ||
providers: [{ provide: HttpClient, useValue: httpClient }], | ||
}); | ||
service = TestBed.inject(ChuckNorrisJokeGeneratorService); | ||
}); | ||
|
||
it('should be created', () => { | ||
expect(service).toBeTruthy(); | ||
}); | ||
|
||
describe('#getJoke()', () => { | ||
it('should return an Observable<Joke>', (done) => { | ||
// Act | ||
service.getJoke().subscribe((joke) => { | ||
// Assert | ||
expect(joke.value).toBe('God prays to Chuck Norris'); | ||
expect(joke.isFavourite).toBeFalse(); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters