Skip to content

Commit

Permalink
Merge pull request #2 from mpeyper/testHook
Browse files Browse the repository at this point in the history
Replace core code with testHook from react-testing-library
  • Loading branch information
mpeyper authored Feb 21, 2019
2 parents 8aa015f + e6854b1 commit 98a9491
Show file tree
Hide file tree
Showing 12 changed files with 511 additions and 339 deletions.
20 changes: 11 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,28 +64,28 @@ const useTheme = (initialTheme) => {
}

// useTheme.test.js
import { useHook, cleanup } from 'react-hooks-testing-library'
import { testHook, cleanup, act } from 'react-hooks-testing-library'

describe('custom hook tests', () => {
afterEach(cleanup)

test('should use theme', () => {
const { getCurrentValue } = useHook(() => useTheme('light'))
const { result } = testHook(() => useTheme('light'))

const theme = getCurrentValue()
const theme = result.current

expect(theme.primaryLight).toBe('#FFFFFF')
expect(theme.primaryDark).toBe('#000000')
})

test('should update theme', () => {
const { getCurrentValue, act } = useHook(() => useTheme('light'))
const { result } = testHook(() => useTheme('light'))

const { toggleTheme } = getCurrentValue()
const { toggleTheme } = result.current

act(() => toggleTheme())

const theme = getCurrentValue()
const theme = result.current

expect(theme.primaryLight).toBe('#000000')
expect(theme.primaryDark).toBe('#FFFFFF')
Expand All @@ -97,11 +97,13 @@ describe('custom hook tests', () => {
dark: { primaryLight: '#CCBBAA', primaryDark: '#AABBCC' }
}

const { getCurrentValue, addContextProvider } = useHook(() => useTheme('light'))
const wrapper = ({ children }) => (
<ThemesContext.Provider value={customThemes}>{children}</ThemesContext.Provider>
)

addContextProvider(ThemesContext, { value: customThemes })
const { result } = testHook(() => useTheme('light'), { wrapper })

const theme = getCurrentValue()
const theme = result.current

expect(theme.primaryLight).toBe('#AABBCC')
expect(theme.primaryDark).toBe('#CCBBAA')
Expand Down
Loading

0 comments on commit 98a9491

Please sign in to comment.