Created
September 22, 2021 10:31
-
-
Save sabesansathananthan/264e7acb5fe98ffb199ff130d5c36675 to your computer and use it in GitHub Desktop.
mock network request in Jest
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" }); | |
}); | |
}); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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