diff --git a/package.json b/package.json
index 7aaf644..25fc579 100644
--- a/package.json
+++ b/package.json
@@ -58,6 +58,7 @@
"@babel/core": "^7.4.5",
"@babel/node": "^7.4.5",
"@babel/preset-env": "^7.4.5",
+ "@react-mock/localstorage": "^0.1.2",
"@svgr/webpack": "^4.3.0",
"@testing-library/jest-dom": "^4.0.0",
"@testing-library/react": "^8.0.2",
diff --git a/src/components/molecules/ThemeSwitch.test.jsx b/src/components/molecules/ThemeSwitch.test.jsx
index d66108a..545becc 100644
--- a/src/components/molecules/ThemeSwitch.test.jsx
+++ b/src/components/molecules/ThemeSwitch.test.jsx
@@ -38,7 +38,9 @@ describe('ThemeSwitch', () => {
)
const toggle = container.querySelector('input')
+ const label = container.querySelector('label')
expect(toggle.checked).toBeFalsy()
+ fireEvent.click(label)
fireEvent.change(toggle, { target: { checked: true } })
expect(toggle.checked).toBeTruthy()
})
diff --git a/src/components/organisms/Repositories.jsx b/src/components/organisms/Repositories.jsx
index ac2d275..7531fd0 100644
--- a/src/components/organisms/Repositories.jsx
+++ b/src/components/organisms/Repositories.jsx
@@ -6,7 +6,7 @@ import styles from './Repositories.module.scss'
export default class Repositories extends PureComponent {
static propTypes = {
- repos: PropTypes.array.isRequired
+ repos: PropTypes.array
}
render() {
diff --git a/src/components/organisms/Repositories.test.jsx b/src/components/organisms/Repositories.test.jsx
index 407afe8..fb1ae48 100644
--- a/src/components/organisms/Repositories.test.jsx
+++ b/src/components/organisms/Repositories.test.jsx
@@ -8,4 +8,9 @@ describe('Repositories', () => {
const { container } = render()
expect(container.firstChild).toBeInTheDocument()
})
+
+ it('return nothing when no repos are passed', () => {
+ const { container } = render()
+ expect(container.firstChild).not.toBeInTheDocument()
+ })
})
diff --git a/src/store/AppProvider.test.jsx b/src/store/AppProvider.test.jsx
index 527ba69..8bc1fb0 100644
--- a/src/store/AppProvider.test.jsx
+++ b/src/store/AppProvider.test.jsx
@@ -1,6 +1,8 @@
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 { Consumer } from './createContext.jsx'
describe('AppProvider', () => {
it('renders correctly', () => {
@@ -8,4 +10,29 @@ describe('AppProvider', () => {
expect(container.firstChild.textContent).toBe('Hello')
})
+
+ it('renders with dark detected in localStorage', () => {
+ const { getByTestId } = render(
+
+
+
+ {state => (
+
+ )}
+
+
+
+ )
+ fireEvent.click(getByTestId('toggle'))
+ })
+
+ it('renders with light detected in localStorage', () => {
+ render(
+
+ Hello
+
+ )
+ })
})