This repository has been archived by the owner on Sep 30, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- set target to es2019 to get the test to compile - minor refactor of cache-file so axios response can be mocked - add .cache and .idea to gitignore Note: this creates a .cache directory as part of the test
- Loading branch information
Showing
4 changed files
with
85 additions
and
9 deletions.
There are no files selected for viewing
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 |
---|---|---|
|
@@ -6,3 +6,5 @@ node_modules | |
*.log | ||
!jest.config.js | ||
coverage/ | ||
.cache | ||
.idea |
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 |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import ImageFile from '../image-file'; | ||
import {GatsbyCache, NodePluginArgs, Store} from 'gatsby'; | ||
import axios, {AxiosResponse} from 'axios'; | ||
|
||
jest.mock('axios'); | ||
|
||
describe('image-file', () => { | ||
const state = { | ||
program: { | ||
directory: '.' | ||
} | ||
}; | ||
|
||
const store: Store = { | ||
dispatch: jest.fn(), | ||
subscribe: jest.fn(), | ||
getState: () => state, | ||
replaceReducer: jest.fn(), | ||
}; | ||
|
||
const cache: NodePluginArgs["cache"] = new class implements GatsbyCache { | ||
get(): Promise<unknown> { | ||
return Promise.resolve(undefined); | ||
} | ||
|
||
set(): Promise<unknown> { | ||
return Promise.resolve(undefined); | ||
} | ||
}; | ||
|
||
describe('getHref', () => { | ||
let params: { | ||
hasSecret: boolean; | ||
markers: string | string[]; | ||
visible: string | string[]; | ||
style: string | string[]; | ||
path: string | string[]; | ||
format: string; | ||
client: string; | ||
}; | ||
|
||
it('with all params', async () => { | ||
const axiosResponse: AxiosResponse = { | ||
data: {}, | ||
status: 200, | ||
statusText: "OK", | ||
config: {}, | ||
headers: {} | ||
}; | ||
|
||
jest.spyOn(axios, "get").mockResolvedValueOnce(axiosResponse); | ||
|
||
params = { | ||
hasSecret: false, | ||
markers: "test-markers", | ||
visible: "test-visible", | ||
style: "test-style", | ||
path: "test-path", | ||
format: "test-format", | ||
client: "test-client", | ||
}; | ||
const imageFile = new ImageFile(cache, params); | ||
|
||
const result = await imageFile.getHref(store, "", "") | ||
|
||
expect(result.hash).toMatch(/client=test-client&/); | ||
expect(result.hash).toMatch(/format=test-format&/); | ||
expect(result.hash).toMatch(/hasSecret=false/); | ||
expect(result.hash).toMatch(/markers=test-markers&/); | ||
expect(result.hash).toMatch(/path=test-path&/); | ||
expect(result.hash).toMatch(/style=test-style&/); | ||
expect(result.hash).toMatch(/visible=test-visible$/); | ||
|
||
expect(result.path).toMatch(/^.cache/); | ||
}); | ||
}); | ||
}); |
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