user.spec.js 625 B

12345678910111213141516171819202122
  1. import { setupPolly } from "setup-polly-jest";
  2. import "whatwg-fetch";
  3. const getPost = async id => {
  4. const response = await fetch(`/posts/${id}`);
  5. const json = await response.json();
  6. return Object.assign(json, { ok: response.ok, status: response.status });
  7. };
  8. describe("user api test", () => {
  9. let context = setupPolly({
  10. /* default configuration options */
  11. });
  12. test("should have polly running with `test`", async () => {
  13. const { server } = context.polly;
  14. server.get("/posts/*path").intercept((req, res) => {
  15. res.send(1);
  16. });
  17. expect(await getPost(1)).toHaveProperty("id", 1);
  18. });
  19. });