Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/__tests__/ThemeProvider.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +107,18 @@ it('defaults to dark color scheme in night mode', () => {
})

it('defaults to first color scheme when passed an invalid color scheme name', () => {
const spy = jest.spyOn(console, 'error').mockImplementationOnce(() => {})

render(
<ThemeProvider theme={exampleTheme} dayScheme="foo">
<Text color="text">Hello</Text>
</ThemeProvider>
)

expect(spy).toHaveBeenCalledWith('`foo` scheme not defined in `theme.colorSchemes`')
expect(screen.getByText('Hello')).toHaveStyleRule('color', 'black')

spy.mockRestore()
})

it('respects nightScheme prop', () => {
Expand Down Expand Up @@ -509,6 +514,7 @@ describe('useTheme().resolvedColorScheme', () => {
})

it('is the value of the fallback colorScheme applied when attempting to apply an invalid colorScheme', () => {
const spy = jest.spyOn(console, 'error').mockImplementationOnce(() => {})
const Component = () => {
const {resolvedColorScheme} = useTheme()

Expand All @@ -524,9 +530,12 @@ describe('useTheme().resolvedColorScheme', () => {

const defaultThemeColorScheme = Object.keys(exampleTheme.colorSchemes)[0]

expect(spy).toHaveBeenCalledWith('`totally-invalid-colorscheme` scheme not defined in `theme.colorSchemes`')
expect(defaultThemeColorScheme).not.toEqual(schemeToApply)
expect(exampleTheme.colorSchemes).not.toHaveProperty(schemeToApply)
expect(screen.getByTestId('text').textContent).toEqual('light')

spy.mockRestore()
})

describe('nested theme', () => {
Expand All @@ -552,6 +561,8 @@ describe('useTheme().resolvedColorScheme', () => {
})

it('is the value of the fallback colorScheme applied when attempting to apply an invalid colorScheme', () => {
const spy = jest.spyOn(console, 'error').mockImplementation(() => {})

const Component = () => {
const {resolvedColorScheme} = useTheme()

Expand All @@ -569,9 +580,12 @@ describe('useTheme().resolvedColorScheme', () => {

const defaultThemeColorScheme = Object.keys(exampleTheme.colorSchemes)[0]

expect(spy).toHaveBeenCalledWith('`totally-invalid-colorscheme` scheme not defined in `theme.colorSchemes`')
expect(defaultThemeColorScheme).not.toEqual(schemeToApply)
expect(exampleTheme.colorSchemes).not.toHaveProperty(schemeToApply)
expect(screen.getByTestId('text').textContent).toEqual('light')

spy.mockRestore()
})
})
})