-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a3809f6
commit 79ae251
Showing
6 changed files
with
598 additions
and
9 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { describe, expect, it } from "vitest" | ||
|
||
|
||
describe("suite", () => { | ||
it("msw mock http://hello", async () => { | ||
const reponse = await fetch( | ||
"https://next-auth-example.com/api/auth/session" | ||
) | ||
const data = await reponse.json() | ||
expect(data).toEqual({ | ||
user: { | ||
name: "John Doe", | ||
email: "[email protected]", | ||
image: "https://next-auth-example.com/avatar.jpg", | ||
}, | ||
}) | ||
}) | ||
}) | ||
|
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { afterAll, afterEach, beforeAll } from "vitest" | ||
import { setupServer } from "msw/node" | ||
import { HttpResponse, http } from "msw" | ||
|
||
const authOptions = [ | ||
|
||
] | ||
|
||
export const restHandlers = [ | ||
http.get("https://next-auth-example.com/api/auth/session", () => { | ||
return HttpResponse.json({ | ||
user: { | ||
name: "John Doe", | ||
email: "[email protected]", | ||
image: "https://next-auth-example.com/avatar.jpg", | ||
}, | ||
}) | ||
}), | ||
] | ||
|
||
const server = setupServer(...restHandlers) | ||
|
||
// Start server before all tests | ||
beforeAll(() => server.listen({ onUnhandledRequest: "error" })) | ||
|
||
// Close server after all tests | ||
afterAll(() => server.close()) | ||
|
||
// Reset handlers after each test `important for test isolation` | ||
afterEach(() => server.resetHandlers()) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/// <reference types="vitest" /> | ||
|
||
import { defineConfig } from 'vite' | ||
|
||
// https://vitejs.dev/config/ | ||
export default defineConfig({ | ||
plugins: [], | ||
test: { | ||
setupFiles: ['./src/test/setup.ts'], | ||
}, | ||
}) |
Oops, something went wrong.