Skip to content

Commit

Permalink
fix!: add CSS styles to DOM (#1690)
Browse files Browse the repository at this point in the history
* fix: add CSS styles to DOM

* chore: set type on style
  • Loading branch information
sheremet-va committed Jul 22, 2022
1 parent 003c87f commit fe69f43
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
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

0 comments on commit fe69f43

Please sign in to comment.