Skip to content

Instantly share code, notes, and snippets.

@brunomacf
Created January 17, 2018 23:06
Show Gist options
  • Save brunomacf/0a75a8c5ced63d7c07d8b79417feecdf to your computer and use it in GitHub Desktop.
Save brunomacf/0a75a8c5ced63d7c07d8b79417feecdf to your computer and use it in GitHub Desktop.
import Fake from "./component";
import {shallow} from "enzyme";
describe("Fake Component", () => {
describe("load method", () => {
describe("on valid url", () => {
it("should set remote object to component state", (done) => {
const url = "http:///.....";
const httpMock = {
request: jest.fn(() => (
new Promise((resolve) => {
setTimeout(() => {
resolve({
hello: "world"
});
}, 1000);
})
))
};
const wrapper = shallow(
<Fake
http={httpMock}
url={url}
/>
);
setTimeout(() => {
const data = Fake.state("data");
expect(httpMock.request).toHavaBeenCalled();
expect(data).toBeDefined();
expect(typeof data).toBe("object");
expect(data.hello).toBe("world");
done();
}, 1500);
});
});
describe("on invalid url", () => {
it("should print an error message inside component body");
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment