mirror of
https://github.com/prymitive/karma
synced 2026-05-07 03:26:52 +00:00
feat(test): add mock modules for fetch() and console
This commit is contained in:
4
ui/src/__mocks__/Console.js
Normal file
4
ui/src/__mocks__/Console.js
Normal file
@@ -0,0 +1,4 @@
|
||||
const ConsoleMock = level =>
|
||||
jest.spyOn(console, level).mockImplementation(() => jest.fn());
|
||||
|
||||
export { ConsoleMock };
|
||||
41
ui/src/__mocks__/Fetch.js
Normal file
41
ui/src/__mocks__/Fetch.js
Normal file
@@ -0,0 +1,41 @@
|
||||
import moment from "moment";
|
||||
|
||||
const FetchMock = data =>
|
||||
jest.fn().mockImplementation(() =>
|
||||
Promise.resolve({
|
||||
json: () => data
|
||||
})
|
||||
);
|
||||
|
||||
const EmptyAPIResponse = () => ({
|
||||
status: "success",
|
||||
timestamp: moment().toISOString(),
|
||||
version: "fakeVersion",
|
||||
upstreams: {
|
||||
counters: { total: 1, healthy: 1, failed: 0 },
|
||||
instances: [{ name: "default", uri: "file:///mock", error: "" }]
|
||||
},
|
||||
silences: { default: {} },
|
||||
groups: {},
|
||||
totalAlerts: 0,
|
||||
colors: {},
|
||||
filters: [
|
||||
{
|
||||
text: "label=value",
|
||||
name: "label",
|
||||
matcher: "=",
|
||||
value: "value",
|
||||
hits: 0,
|
||||
isValid: true
|
||||
}
|
||||
],
|
||||
counters: {},
|
||||
settings: {
|
||||
staticColorLabels: ["job"],
|
||||
annotationsDefaultHidden: false,
|
||||
annotationsHidden: [],
|
||||
annotationsVisible: []
|
||||
}
|
||||
});
|
||||
|
||||
export { FetchMock, EmptyAPIResponse };
|
||||
Reference in New Issue
Block a user