Back
Syntax
Study
Editor
Mode:
HTML
CSS
JavaScript
PHP
Reset
Run »
HTML / CSS / JS
test("fetches user", async () => { global.fetch = jest.fn().mockResolvedValue({ ok: true, json: async () => ({ id: 1, name: "Alice" }), }); const user = await loadUser(1); expect(user.name).toBe("Alice"); expect(fetch).toHaveBeenCalledWith("/api/users/1"); });
Result
Open