mirror of
https://github.com/kremalicious/portfolio.git
synced 2025-01-03 18:35:00 +01:00
increase test coverage
This commit is contained in:
parent
62152681f6
commit
1cdc34f216
@ -58,6 +58,7 @@
|
|||||||
"@babel/core": "^7.4.5",
|
"@babel/core": "^7.4.5",
|
||||||
"@babel/node": "^7.4.5",
|
"@babel/node": "^7.4.5",
|
||||||
"@babel/preset-env": "^7.4.5",
|
"@babel/preset-env": "^7.4.5",
|
||||||
|
"@react-mock/localstorage": "^0.1.2",
|
||||||
"@svgr/webpack": "^4.3.0",
|
"@svgr/webpack": "^4.3.0",
|
||||||
"@testing-library/jest-dom": "^4.0.0",
|
"@testing-library/jest-dom": "^4.0.0",
|
||||||
"@testing-library/react": "^8.0.2",
|
"@testing-library/react": "^8.0.2",
|
||||||
|
@ -38,7 +38,9 @@ describe('ThemeSwitch', () => {
|
|||||||
)
|
)
|
||||||
|
|
||||||
const toggle = container.querySelector('input')
|
const toggle = container.querySelector('input')
|
||||||
|
const label = container.querySelector('label')
|
||||||
expect(toggle.checked).toBeFalsy()
|
expect(toggle.checked).toBeFalsy()
|
||||||
|
fireEvent.click(label)
|
||||||
fireEvent.change(toggle, { target: { checked: true } })
|
fireEvent.change(toggle, { target: { checked: true } })
|
||||||
expect(toggle.checked).toBeTruthy()
|
expect(toggle.checked).toBeTruthy()
|
||||||
})
|
})
|
||||||
|
@ -6,7 +6,7 @@ import styles from './Repositories.module.scss'
|
|||||||
|
|
||||||
export default class Repositories extends PureComponent {
|
export default class Repositories extends PureComponent {
|
||||||
static propTypes = {
|
static propTypes = {
|
||||||
repos: PropTypes.array.isRequired
|
repos: PropTypes.array
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
|
@ -8,4 +8,9 @@ describe('Repositories', () => {
|
|||||||
const { container } = render(<Repositories repos={repos} />)
|
const { container } = render(<Repositories repos={repos} />)
|
||||||
expect(container.firstChild).toBeInTheDocument()
|
expect(container.firstChild).toBeInTheDocument()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('return nothing when no repos are passed', () => {
|
||||||
|
const { container } = render(<Repositories />)
|
||||||
|
expect(container.firstChild).not.toBeInTheDocument()
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
import React from 'react'
|
import React from 'react'
|
||||||
import { render } from '@testing-library/react'
|
import { render, fireEvent } from '@testing-library/react'
|
||||||
|
import { LocalStorageMock } from '@react-mock/localstorage'
|
||||||
import AppProvider from './AppProvider.jsx'
|
import AppProvider from './AppProvider.jsx'
|
||||||
|
import { Consumer } from './createContext.jsx'
|
||||||
|
|
||||||
describe('AppProvider', () => {
|
describe('AppProvider', () => {
|
||||||
it('renders correctly', () => {
|
it('renders correctly', () => {
|
||||||
@ -8,4 +10,29 @@ describe('AppProvider', () => {
|
|||||||
|
|
||||||
expect(container.firstChild.textContent).toBe('Hello')
|
expect(container.firstChild.textContent).toBe('Hello')
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('renders with dark detected in localStorage', () => {
|
||||||
|
const { getByTestId } = render(
|
||||||
|
<LocalStorageMock items={{ dark: 'true' }}>
|
||||||
|
<AppProvider>
|
||||||
|
<Consumer>
|
||||||
|
{state => (
|
||||||
|
<button data-testid="toggle" onClick={() => state.toggleDark()}>
|
||||||
|
Toggle
|
||||||
|
</button>
|
||||||
|
)}
|
||||||
|
</Consumer>
|
||||||
|
</AppProvider>
|
||||||
|
</LocalStorageMock>
|
||||||
|
)
|
||||||
|
fireEvent.click(getByTestId('toggle'))
|
||||||
|
})
|
||||||
|
|
||||||
|
it('renders with light detected in localStorage', () => {
|
||||||
|
render(
|
||||||
|
<LocalStorageMock items={{ dark: 'false' }}>
|
||||||
|
<AppProvider>Hello</AppProvider>
|
||||||
|
</LocalStorageMock>
|
||||||
|
)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user