1- import { describe , it , expect , beforeAll , afterEach , afterAll } from "vitest"
1+ import { describe , it , vi , expect , beforeAll , afterEach , afterAll } from "vitest"
22import { cleanup , render , screen } from "@testing-library/react"
33import { PasteBin } from "../components/PasteBin.js"
44
@@ -21,6 +21,7 @@ export const server = setupServer(
2121)
2222
2323beforeAll ( ( ) => {
24+ stubBrowerFunctions ( )
2425 server . listen ( )
2526} )
2627
@@ -30,6 +31,7 @@ afterEach(() => {
3031} )
3132
3233afterAll ( ( ) => {
34+ unStubBrowerFunctions ( )
3335 server . close ( )
3436} )
3537
@@ -38,6 +40,7 @@ import { userEvent } from "@testing-library/user-event"
3840import { PasteResponse } from "../../shared/interfaces.js"
3941import { setupServer } from "msw/node"
4042import { http , HttpResponse } from "msw"
43+ import { stubBrowerFunctions , unStubBrowerFunctions } from "./testUtils.js"
4144
4245describe ( "Pastebin" , ( ) => {
4346 it ( "can upload" , async ( ) => {
@@ -74,11 +77,7 @@ describe("Pastebin", () => {
7477
7578describe ( "Pastebin admin page" , ( ) => {
7679 it ( "renders admin page" , async ( ) => {
77- Object . defineProperty ( window , "location" , {
78- configurable : true ,
79- enumerable : true ,
80- value : new URL ( "https://example.com/abcd:xxxxxxxxx" ) ,
81- } )
80+ vi . stubGlobal ( "location" , new URL ( "https://example.com/abcd:xxxxxxxxx" ) )
8281 render ( < PasteBin /> )
8382
8483 const editor = screen . getByRole ( "textbox" , { name : "Paste editor" } )
0 commit comments