Ask questions Error on unit test : Cannot read property 'Symbol(Symbol.iterator)' of undefined

@gaearon i have a component that has a useState hooks as below :

component is so big , because of that , i just write some of the problem .

function Login(props){
    const [, dispatch] = useLoginStateValue();


and i have a test for this component


it("mock login request testing", (done) => {
    act(() => {
        const wrapper = mount(
            <MuiThemeProvider theme={dark}>
                <Login theme={{isResponsive: true}}/>

        wrapper.setState({email: "@@22WWee"})
        wrapper.setState({password: ""})

        setTimeout(() => {
            wrapper.setState({alert: "Bad credentials"})
            expect(wrapper.instance().state.alert).toEqual("Bad credentials")

when i run test , it shows error : Error: Uncaught [TypeError: Cannot read property 'Symbol(Symbol.iterator)' of undefined]

after removing const [, dispatch] = useLoginStateValue(); everything is ok , how can i use dispatch , and LoginStateValue without error in test ?


Answer questions threepointone

My guess is that useLoginStateValue doesn't return an array. Would recommend using a community resource for questions like this


Related questions

Disable react strict mode on third party libraries hot 7
Warning: Unknown DOM property for. Did you mean htmlFor? hot 6
TypeError: Object(...) is not a function
Refs - &#34;object is not extensible&#34;
React@16.9 block `javascript:void(0);`
Warning: validateDOMNesting(...): <tr> cannot appear as a child of <table> hot 3
"DevTools v4 is incompatible with this version of React" with React Native & latest version of React hot 3
Feedback on useEffect depndencies change error hot 3
[ESLint] Feedback for 'exhaustive-deps' lint rule hot 3
React custom hook "Should have a queue. This is likely a bug in React" error message. hot 2
useEffect causes 'callback is not a function' exception hot 2
DevTools: Updating state or props in devtools does not trigger component update. hot 2
Infinite loop in useEffect using blank object or array hot 2
False-positive security precaution warning (`javascript:` URLs) hot 2
Hooks API - hook breaks when exported from module hot 2
Github User Rank List