Skip to content

Instantly share code, notes, and snippets.

@sabesansathananthan
Created September 22, 2021 10:31
Show Gist options
  • Save sabesansathananthan/264e7acb5fe98ffb199ff130d5c36675 to your computer and use it in GitHub Desktop.
Save sabesansathananthan/264e7acb5fe98ffb199ff130d5c36675 to your computer and use it in GitHub Desktop.
mock network request in Jest
import { counter } from "./demo";
import { setSuitesData } from "../src/index";
import data from "./data/demo1.data";
beforeAll(() => {
return setSuitesData(data);
});
describe("Simple mock", () => {
it("test success", () => {
return counter(1, 2).then(res => {
expect(res).toStrictEqual({ result: 0, msg: "success" });
});
});
it("test need login", () => {
return counter(2, -3).then(res => {
expect(res).toStrictEqual({ result: -100, msg: "need login" });
});
});
});
import { counter } from "./demo";
import { setSuitesData } from "../src/index";
import data from "./data/demo2.data";
beforeAll(() => {
return setSuitesData(data);
});
describe("Simple mock", () => {
it("test success", () => {
return counter(3, -30).then(res => {
expect(res).toStrictEqual({ result: -100, msg: "need login" });
});
});
it("test no match response", () => {
return counter(6, 2).then(res => {
expect(res).toStrictEqual({ result: -999, msg: "fail" });
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment