Files
modeling-app/src/App.test.tsx

50 lines
1.3 KiB
TypeScript
Raw Normal View History

2022-11-26 08:34:23 +11:00
import { render, screen } from '@testing-library/react'
import { App } from './App'
import { describe, test, vi } from 'vitest'
import { BrowserRouter } from 'react-router-dom'
import { GlobalStateProvider } from './hooks/useAuthMachine'
2022-11-12 13:11:54 +11:00
2022-11-26 08:34:23 +11:00
let listener: ((rect: any) => void) | undefined = undefined
;(global as any).ResizeObserver = class ResizeObserver {
constructor(ls: ((rect: any) => void) | undefined) {
2022-11-26 08:34:23 +11:00
listener = ls
}
observe() {}
unobserve() {}
disconnect() {}
2022-11-26 08:34:23 +11:00
}
describe('App tests', () => {
test('Renders the modeling app screen, including "Variables" pane.', () => {
vi.mock('react-router-dom', async () => {
const actual = (await vi.importActual('react-router-dom')) as Record<
string,
any
>
return {
...actual,
useParams: () => ({ id: 'new' }),
useLoaderData: () => ({ code: null }),
}
})
render(
<TestWrap>
<App />
</TestWrap>
)
const linkElement = screen.getByText(/Variables/i)
expect(linkElement).toBeInTheDocument()
vi.restoreAllMocks()
})
2022-11-26 08:34:23 +11:00
})
function TestWrap({ children }: { children: React.ReactNode }) {
// wrap in router and xState context
return (
<BrowserRouter>
<GlobalStateProvider>{children}</GlobalStateProvider>
</BrowserRouter>
)
}