Skip to content

Commit

Permalink
refactor: better tests for make-href pipe
Browse files Browse the repository at this point in the history
  • Loading branch information
Eisie96 committed Sep 5, 2023
1 parent 1f4d166 commit 1f81d5a
Showing 1 changed file with 19 additions and 11 deletions.
30 changes: 19 additions & 11 deletions src/app/core/pipes/make-href.pipe.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ describe('Make Href Pipe', () => {
providers: [{ provide: MultiSiteService, useFactory: () => instance(multiSiteService) }, MakeHrefPipe],
});
makeHrefPipe = TestBed.inject(MakeHrefPipe);

when(multiSiteService.getLangUpdatedUrl(anything(), anything())).thenCall((url: string, _: LocationStrategy) =>
of(url)
);
Expand All @@ -28,24 +29,31 @@ describe('Make Href Pipe', () => {
it('should be created', () => {
expect(makeHrefPipe).toBeTruthy();
});
// workaround for https://github.com/DefinitelyTyped/DefinitelyTyped/issues/34617
// eslint-disable-next-line @typescript-eslint/no-explicit-any
it.each<any | jest.DoneCallback>([
[undefined, undefined, 'undefined'],
['/test', undefined, '/test'],
])(`should transform "%s" with %j to "%s"`, (url, params, expected, done: jest.DoneCallback) => {
makeHrefPipe.transform({ path: () => url, getBaseHref: () => '/' } as LocationStrategy, params).subscribe(res => {
expect(res).toEqual(expected);
done();
});

it('should call appendUrlParams from the multiSiteService if no parameter exists', done => {
makeHrefPipe
.transform({ path: () => '/de/test', getBaseHref: () => '/de' } as LocationStrategy, undefined)
.subscribe(() => {
verify(multiSiteService.appendUrlParams(anything(), anything(), anything())).once();
done();
});
});

it('should call the multiSiteService if lang parameter exists', done => {
it('should call getLangUpdatedUrl from the multiSiteService if lang parameter exists', done => {
makeHrefPipe
.transform({ path: () => '/de/test', getBaseHref: () => '/de' } as LocationStrategy, { lang: 'en_US' })
.subscribe(() => {
verify(multiSiteService.getLangUpdatedUrl(anything(), anything())).once();
done();
});
});

it('should call appendUrlParams from the multiSiteService if other parameter exists', done => {
makeHrefPipe
.transform({ path: () => '/de/test', getBaseHref: () => '/de' } as LocationStrategy, { foo: 'bar' })
.subscribe(() => {
verify(multiSiteService.appendUrlParams(anything(), anything(), anything())).once();
done();
});
});
});

0 comments on commit 1f81d5a

Please sign in to comment.