Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix!: add CSS styles to DOM #1690

Merged
merged 2 commits into from
Jul 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions examples/react-testing-lib/src/App.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,11 @@ describe('Simple working test', () => {
userEvent.click(screen.getByRole('button'))
expect(await screen.findByText(/count is: 1/i)).toBeInTheDocument()
})

it('uses flexbox in app header', async () => {
render(<App />)
const element = screen.getByRole('banner')
expect(element.className).toEqual('App-header')
expect(getComputedStyle(element).display).toEqual('flex')
})
})
3 changes: 3 additions & 0 deletions examples/react-testing-lib/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,8 @@ export default defineConfig({
globals: true,
environment: 'jsdom',
setupFiles: './src/test/setup.ts',
// you might want to disable it, if you don't have tests that rely on CSS
// since parsing CSS is slow
css: true,
},
})
16 changes: 15 additions & 1 deletion packages/vite-node/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,21 @@ export const DEFAULT_REQUEST_STUBS = {
on: () => {},
}
},
updateStyle() {},
updateStyle(id: string, css: string) {
if (typeof document === 'undefined')
return

const element = document.getElementById(id)
if (element)
element.remove()

const head = document.querySelector('head')
const style = document.createElement('style')
style.setAttribute('type', 'text/css')
style.id = id
style.innerHTML = css
head?.appendChild(style)
},
},
}

Expand Down