Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: transform test/components/hooks to tsx #1769

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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