Skip to content
This repository has been archived by the owner on Jan 9, 2023. It is now read-only.

Commit

Permalink
feat(init): remove warnings in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jackcmeyer committed Nov 29, 2019
1 parent 2edfe1b commit 3d7be47
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 5 deletions.
2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
"react-router-dom": "~5.1.2",
"react-scripts": "~3.2.0",
"redux": "~4.0.4",
"redux-logger": "~3.0.6",
"redux-thunk": "~2.3.0",
"typescript": "~3.6.3"
},
Expand Down Expand Up @@ -56,7 +55,6 @@
"@types/react-redux": "^7.1.5",
"@types/react-router": "~5.1.2",
"@types/react-router-dom": "~5.1.0",
"@types/redux-logger": "^3.0.7",
"@typescript-eslint/eslint-plugin": "~2.9.0",
"@typescript-eslint/parser": "~2.9.0",
"commitizen": "~4.0.3",
Expand Down
53 changes: 53 additions & 0 deletions src/__mocks__/react-i18next.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/* eslint-disable */
const React = require('react')
const reactI18next = require('react-i18next')

const hasChildren = (node) => node && (node.children || (node.props && node.props.children))

const getChildren = (node) =>
node && node.children ? node.children : node.props && node.props.children

const renderNodes = (reactNodes) => {
if (typeof reactNodes === 'string') {
return reactNodes
}

return Object.keys(reactNodes).map((key, i) => {
const child = reactNodes[key]
const isElement = React.isValidElement(child)

if (typeof child === 'string') {
return child
}
if (hasChildren(child)) {
const inner = renderNodes(getChildren(child))
return React.cloneElement(child, { ...child.props, key: i }, inner)
}
if (typeof child === 'object' && !isElement) {
return Object.keys(child).reduce((str, childKey) => `${str}${child[childKey]}`, '')
}

return child
})
}

const useMock = [(k) => k, {}]
useMock.t = (k) => k
useMock.i18n = {}

module.exports = {
// this mock makes sure any components using the translate HoC receive the t function as a prop
withTranslation: () => (Component) => (props) => <Component t={(k) => k} {...props} />,
Trans: ({ children }) => renderNodes(children),
Translation: ({ children }) => children((k) => k, { i18n: {} }),
useTranslation: () => useMock,

// mock if needed
I18nextProvider: reactI18next.I18nextProvider,
initReactI18next: reactI18next.initReactI18next,
setDefaults: reactI18next.setDefaults,
getDefaults: reactI18next.getDefaults,
setI18n: reactI18next.setI18n,
getI18n: reactI18next.getI18n,
}

4 changes: 1 addition & 3 deletions src/store/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { configureStore, combineReducers, Action } from '@reduxjs/toolkit'
import ReduxThunk, { ThunkAction } from 'redux-thunk'
import { createLogger } from 'redux-logger'

import patient from '../slices/patient-slice'
import patients from '../slices/patients-slice'
import title from '../slices/title-slice'
Expand All @@ -16,7 +14,7 @@ const reducer = combineReducers({

const store = configureStore({
reducer,
middleware: [ReduxThunk, createLogger()],
middleware: [ReduxThunk],
})

export type AppDispatch = typeof store.dispatch
Expand Down

0 comments on commit 3d7be47

Please sign in to comment.