basic layout test

This commit is contained in:
Matthias Kretschmann 2024-02-01 18:26:00 +00:00
parent d1e417b9d7
commit 64b835a59a
Signed by: m
GPG Key ID: 606EEEF3C479A91F
3 changed files with 26 additions and 6 deletions

View File

@ -0,0 +1,24 @@
import { render, screen } from '@testing-library/react'
import { dataLocation } from '../../../tests/__fixtures__/location'
import Layout from '../layout'
describe('app: /layout', () => {
// suppress error "Warning: validateDOMNesting(...): <html> cannot appear as a child of <div>"
// https://github.com/testing-library/react-testing-library/issues/1250
let originalError
beforeAll(() => {
originalError = console.error
console.error = jest.fn()
})
afterAll(() => {
console.error = originalError
})
it('renders correctly', async () => {
render(<Layout>Hello</Layout>)
await screen.findByText(dataLocation.now.city)
})
})

View File

@ -1,3 +1,4 @@
import { ReactNode } from 'react'
import { Metadata, Viewport } from 'next'
import Script from 'next/script'
import meta from '../../_content/meta.json'
@ -35,11 +36,7 @@ export const viewport: Viewport = {
themeColor: 'var(--theme-color)'
}
export default function RootLayout({
children
}: {
children: React.ReactNode
}) {
export default function RootLayout({ children }: { children: ReactNode }) {
return (
<html lang="en" suppressHydrationWarning>
<head>

View File

@ -11,7 +11,6 @@ import { UseLocation } from './types'
export default function Location() {
const shouldReduceMotion = useReducedMotion()
const [location, setLocation] = useState<UseLocation>()
const isDifferentCountry = location?.now?.country !== location?.next?.country