Tests for callbacks

This commit is contained in:
Rick Carlino 2017-10-24 16:42:20 -05:00
parent e414245a51
commit a8ec926d41
2 changed files with 18 additions and 8 deletions

View file

@ -84,5 +84,11 @@ describe("fetchLabFeatures", () => {
const val = fetchLabFeatures();
expect(val.length).toBe(6);
expect(val[0].value).toBeFalsy();
const { callback } = val[0];
if (callback) {
expect(callback()).not.toThrowError();
} else {
expect(callback).toBeDefined();
}
});
});

View file

@ -1,13 +1,16 @@
const mockFeatures = [
{
name: "Weed Detection",
description: "Plots points of weeds in the garden.",
storageKey: "weedDetector",
callback: jest.fn(),
value: false
}
];
const mocks = {
"maybeToggleFeature": jest.fn(),
"fetchLabFeatures": jest.fn(() => ([
{
name: "Weed Detection",
description: "Plots points of weeds in the garden.",
storageKey: "weedDetector",
value: false
}
]))
"fetchLabFeatures": jest.fn(() => mockFeatures)
};
jest.mock("../labs_features_list_data", () => mocks);
@ -21,6 +24,7 @@ describe("<LabsFeatures/>", () => {
const el = mount(<LabsFeatures />);
expect(mocks.fetchLabFeatures.mock.calls.length).toBeGreaterThan(0);
el.find("button").simulate("click");
expect(mockFeatures[0].callback).toHaveBeenCalled();
expect(mocks.maybeToggleFeature.mock.calls.length).toBeGreaterThan(0);
});
});