feat(test): add mock modules for fetch() and console

This commit is contained in:
Łukasz Mierzwa
2018-08-21 18:36:56 +01:00
parent 3fcbee1067
commit 9fe6494830
2 changed files with 45 additions and 0 deletions

View 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
View 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 };