Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
refactor: clean up eventsource mock
  • Loading branch information
jsjoeio committed Sep 29, 2022
commit a4769d8aba3a42f01c8734748272d02a59f6b9c7
17 changes: 12 additions & 5 deletions site/src/pages/WorkspacePage/WorkspacePage.test.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { fireEvent, screen, waitFor } from "@testing-library/react"
import userEvent from "@testing-library/user-event"
import EventSource from "eventsourcemock"
import EventSourceMock from "eventsourcemock"
import i18next from "i18next"
import { rest } from "msw"
import * as api from "../../api/api"
Expand Down Expand Up @@ -70,13 +70,20 @@ const testStatus = async (ws: Workspace, label: string) => {
expect(status).toHaveTextContent(label)
}

let originalEventSource: typeof window.EventSource

beforeAll(() => {
originalEventSource = window.EventSource
// mocking out EventSource for SSE
window.EventSource = EventSourceMock
})

beforeEach(() => {
jest.resetAllMocks()
})

// mocking out EventSource for SSE
Object.defineProperty(window, "EventSource", {
value: EventSource,
})
afterAll(() => {
window.EventSource = originalEventSource
})

describe("WorkspacePage", () => {
Expand Down