Created
February 20, 2023 08:12
-
-
Save ruizalexandre/2a3c6140b33984d29b41194c80098bd2 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| import { HttpClient } from "@angular/common/http"; | |
| import { TestBed } from "@angular/core/testing"; | |
| import { of } from "rxjs"; | |
| import { TranslocoHttpLoader } from "./transloco.root.service"; | |
| describe(TranslocoHttpLoader.name, () => { | |
| let httpClientSpy: jasmine.SpyObj<HttpClient>; | |
| let translocoHttpLoader: TranslocoHttpLoader; | |
| beforeEach(() => { | |
| const spy = jasmine.createSpyObj('HttpClient', ['get']); | |
| TestBed.configureTestingModule({ | |
| providers: [ | |
| TranslocoHttpLoader, { | |
| provide: HttpClient, | |
| useValue: spy | |
| }] | |
| }); | |
| translocoHttpLoader = TestBed.inject(TranslocoHttpLoader); | |
| httpClientSpy = TestBed.inject(HttpClient) as jasmine.SpyObj<HttpClient>; | |
| }); | |
| it('should fetch language', done => { | |
| httpClientSpy.get.and.returnValue(of({ | |
| key1: 'KEY 1', | |
| key2: 'KEY 2' | |
| })); | |
| translocoHttpLoader | |
| .getTranslation('fakeLanguage') | |
| .subscribe({ | |
| next: (value) => { | |
| expect(value).toEqual({ | |
| key1: 'KEY 1', | |
| key2: 'KEY 2' | |
| }) | |
| done(); | |
| }, | |
| error: done.fail | |
| }); | |
| expect(httpClientSpy.get.calls.count()) | |
| .withContext('one call') | |
| .toBe(1); | |
| }); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment