Skip to content

Commit

Permalink
progress: fix test by mocking Web Worker
Browse files Browse the repository at this point in the history
  • Loading branch information
trentrand committed Jul 15, 2024
1 parent d7030e2 commit 33a19db
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 4 deletions.
1 change: 0 additions & 1 deletion src/pages/index/+Page.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import fastbootPorts from '../../assets/fastboot-ports.svg'
import zadigCreateNewDevice from '../../assets/zadig_create_new_device.png'
import zadigForm from '../../assets/zadig_form.png'


export default function App() {
const version = import.meta?.env?.VITE_PUBLIC_GIT_SHA ?? 'dev'
console.info(`flash.comma.ai version: ${version}`)
Expand Down
5 changes: 2 additions & 3 deletions src/pages/index/Page.test.jsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { Suspense } from 'react'
import { expect, test } from 'vitest'
import { render, screen } from '@testing-library/react'

import App from '.'
import Page from './+Page'

test('renders without crashing', () => {
render(<Suspense fallback="loading"><App /></Suspense>)
render(<Suspense fallback="loading"><Page /></Suspense>)
expect(screen.getByText('flash.comma.ai')).toBeInTheDocument()
})
16 changes: 16 additions & 0 deletions src/test/mockWorker.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
class MockWorker {
constructor(stringUrl) {
this.url = stringUrl;
this.onmessage = () => {};
}

postMessage(msg) {
this.onmessage({ data: msg });
}

addEventListener() {}
removeEventListener() {}
terminate() {}
}

export default MockWorker;
3 changes: 3 additions & 0 deletions src/test/setup.js
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
import '@testing-library/jest-dom'
import MockWorker from './mockWorker';

global.Worker = MockWorker

0 comments on commit 33a19db

Please sign in to comment.