Skip to content

Commit

Permalink
refactor: transform test/components/hooks to tsx (#1769)
Browse files Browse the repository at this point in the history
  • Loading branch information
myNameIsDu committed Jul 15, 2021
1 parent f1201de commit cc63d0c
Showing 1 changed file with 42 additions and 20 deletions.
62 changes: 42 additions & 20 deletions test/components/hooks.spec.js → test/components/hooks.spec.tsx
Expand Up @@ -5,46 +5,60 @@ import { createStore } from 'redux'
import { Provider as ProviderMock, connect } from '../../src/index'
import * as rtl from '@testing-library/react'
import '@testing-library/jest-dom/extend-expect'
import type { AnyAction } from 'redux'

describe('React', () => {
describe('connect', () => {
afterEach(() => rtl.cleanup())

it('should render on useEffect hook state update', () => {
const store = createStore((state, action) => {
let newState =
state !== undefined
? state
: {
byId: {},
list: [],
interface RootStateType {
byId: {
[x: string]: string
}
list: Array<number>
}
const store = createStore<RootStateType, AnyAction, unknown, unknown>(
(state, action) => {
let newState =
state !== undefined
? state
: {
byId: {},
list: [],
}
switch (action.type) {
case 'FOO':
newState = {
...newState,
list: [1],
byId: { 1: 'foo' },
}
switch (action.type) {
case 'FOO':
newState = {
...newState,
list: [1],
byId: { 1: 'foo' },
}
break
break
}
return newState
}
return newState
})
)

const mapStateSpy1 = jest.fn()
const renderSpy1 = jest.fn()

let component1StateList

const component1Decorator = connect((state) => {
const component1Decorator = connect<
Omit<RootStateType, 'byId'>,
unknown,
unknown,
RootStateType
>((state) => {
mapStateSpy1()

return {
list: state.list,
}
})

const component1 = (props) => {
const component1 = (props: Omit<RootStateType, 'byId'>) => {
const [state, setState] = React.useState({ list: props.list })

component1StateList = state.list
Expand All @@ -63,7 +77,15 @@ describe('React', () => {
const mapStateSpy2 = jest.fn()
const renderSpy2 = jest.fn()

const component2Decorator = connect((state, ownProps) => {
interface Component2PropsType {
mappedProp: Array<string>
}
const component2Decorator = connect<
Component2PropsType,
unknown,
Omit<RootStateType, 'byId'>,
RootStateType
>((state, ownProps) => {
mapStateSpy2()

return {
Expand Down

0 comments on commit cc63d0c

Please sign in to comment.