Skip to content

Commit

Permalink
reafctor: delete some obsolete cases that have been skipped
Browse files Browse the repository at this point in the history
  • Loading branch information
myNameIsDu committed Jul 31, 2021
1 parent bc70ffb commit c9a5b8f
Showing 1 changed file with 0 additions and 168 deletions.
168 changes: 0 additions & 168 deletions test/components/connect.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1761,141 +1761,6 @@ describe('React', () => {
})
})

describe('HMR handling', () => {
it.skip('should recalculate the state and rebind the actions on hot update', () => {
const store = createStore(() => {})
class ContainerBefore extends Component {
render() {
return <Passthrough {...this.props} />
}
}
const ConnectedContainerBefore = connect(null, () => ({
scooby: 'doo',
}))(ContainerBefore)
class ContainerAfter extends Component {
render() {
return <Passthrough {...this.props} />
}
}
const ConnectedContainerAfter = connect(
() => ({ foo: 'baz' }),
() => ({ scooby: 'foo' })
)(ContainerAfter)
class ContainerNext extends Component {
render() {
return <Passthrough {...this.props} />
}
}
const ConnectedContainerNext = connect(
() => ({ foo: 'bar' }),
() => ({ scooby: 'boo' })
)(ContainerNext)

let container = React.createRef<ContainerBefore>()
const tester = rtl.render(
<ProviderMock store={store}>
<ConnectedContainerBefore ref={container} />
</ProviderMock>
)
expect(tester.queryByTestId('foo')).toBe(null)
expect(tester.getByTestId('scooby')).toHaveTextContent('doo')
imitateHotReloading(
ConnectedContainerBefore,
ConnectedContainerAfter,
container.current!
)
expect(tester.getByTestId('foo')).toHaveTextContent('baz')
expect(tester.getByTestId('scooby')).toHaveTextContent('foo')
imitateHotReloading(
ConnectedContainerBefore,
ConnectedContainerNext,
container.current!
)
expect(tester.getByTestId('foo')).toHaveTextContent('bar')
expect(tester.getByTestId('scooby')).toHaveTextContent('boo')
})

it.skip('should persist listeners through hot update', () => {
const ACTION_TYPE = 'ACTION'
interface RootStateType {
actions: number
}
interface ActionType {
type: string
}
const store = createStore(
(state: RootStateType = { actions: 0 }, action: ActionType) => {
switch (action.type) {
case ACTION_TYPE: {
return {
actions: state.actions + 1,
}
}
default:
return state
}
}
)

class Child extends Component {
render() {
return <Passthrough {...this.props} />
}
}
interface ChildrenTStateProps {
actions: number
}
type ChildrenNoDispatch = {}
type ChildrenTOwnProps = {}
type ChildrenRootState = RootStateType
const ConnectedChild = connect<
ChildrenTStateProps,
ChildrenNoDispatch,
ChildrenTOwnProps,
ChildrenRootState
>((state) => ({
actions: state.actions,
}))(Child)

class ParentBefore extends Component {
render() {
return <ConnectedChild />
}
}
const ConnectedParentBefore = connect(() => ({ scooby: 'doo' }))(
ParentBefore
)

class ParentAfter extends Component {
render() {
return <Child />
}
}
const ConnectedParentAfter = connect(() => ({ scooby: 'boo' }))(
ParentAfter
)

let container = React.createRef<ParentBefore>()
const tester = rtl.render(
<ProviderMock store={store}>
<ConnectedParentBefore ref={container} />
</ProviderMock>
)

imitateHotReloading(
ConnectedParentBefore,
ConnectedParentAfter,
container.current!
)

rtl.act(() => {
store.dispatch({ type: ACTION_TYPE })
})

expect(tester.getByTestId('actions')).toHaveTextContent('1')
})
})

describe('Wrapped component and HOC handling', () => {
it('should throw an error if a component is not passed to the function returned by connect', () => {
expect(connect()).toThrow(/You must pass a component to the function/)
Expand Down Expand Up @@ -2668,39 +2533,6 @@ describe('React', () => {
})

describe('Refs', () => {
// it.skip('should throw when trying to access the wrapped instance if withRef is not specified', () => {
// const store = createStore(() => ({}))

// class Container extends Component {
// render() {
// return <Passthrough />
// }
// }

// const decorator = connect((state) => state)
// const Decorated = decorator(Container)

// class Wrapper extends Component {
// render() {
// return (
// <Decorated ref={(comp) => comp && comp.getWrappedInstance()} />
// )
// }
// }

// // TODO Remove this when React is fixed, per https://github.com/facebook/react/issues/11098
// const spy = jest.spyOn(console, 'error').mockImplementation(() => {})
// expect(() =>
// rtl.render(
// <ProviderMock store={store}>
// <Wrapper />
// </ProviderMock>
// )
// ).toThrow(
// `To access the wrapped instance, you need to specify { withRef: true } in the options argument of the connect() call`
// )
// spy.mockRestore()
// })
it('should return the instance of the wrapped component for use in calling child methods', async (done) => {
const store = createStore(() => ({}))

Expand Down

0 comments on commit c9a5b8f

Please sign in to comment.