Skip to content

Instantly share code, notes, and snippets.

@ruizalexandre
Created February 20, 2023 08:12
Show Gist options
  • Select an option

  • Save ruizalexandre/2a3c6140b33984d29b41194c80098bd2 to your computer and use it in GitHub Desktop.

Select an option

Save ruizalexandre/2a3c6140b33984d29b41194c80098bd2 to your computer and use it in GitHub Desktop.
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