Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 42 additions & 20 deletions test/components/hooks.spec.js → test/components/hooks.spec.tsx
Original file line number Diff line number Diff line change
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