Skip to content

Instantly share code, notes, and snippets.

@qfarenwald
Last active February 1, 2020 00:14
Show Gist options
  • Save qfarenwald/b04d5217227e2636822157366b9e6350 to your computer and use it in GitHub Desktop.
Save qfarenwald/b04d5217227e2636822157366b9e6350 to your computer and use it in GitHub Desktop.

Common Error Notes

Testing

ERROR:

TypeError: Cannot read property 'map' of undefined

Solution:

?

ERROR:

Timeout - Async callback was not invoked within the 5000ms timeout specified by jest.setTimeout.Timeout - Async callback was not invoked within the 5000ms timeout specified by jest.setTimeout

Solution:

window.fetch = jest.fn().mockImplementation(() => {
  return Promise.resolve({
    ok: true,
    json: () => Promise.resolve(mockResponse)
  });
});

ERROR:

TypeError: wrapper.instance(...).actionName is not a function

or

actionName is not a function

Solution:

const wrapper = shallow(<Component actionName={mockActionName}/>)

ERROR:

Matcher error: received value must be a mock or spy function

Solution:

const filteredTrailData = jest.fn()

ERROR:

ReferenceError: filteredTrailData is not defined

Solution: import function from other file, like helpers or actions at top of test file

import { filteredTrailData } from './utils/helpers';

ERROR:

expect(jest.fn()).toHaveBeenCalled()

    Expected number of calls: >= 1
    Received number of calls:    0

// BAD
<Link to="/trails" onClick={() => props.getLatLon(40.0150, 105.2705)}><button className="Location-btn">BOULDER</button></Link>

Solution:

// make sure onClick is being called on button... not link
<Link to="/trails"><button onClick={() => props.getLatLon(40.0150, 105.2705)} className="Location-btn">BOULDER</button></Link>

OR

// force the update in the set up
wrapper.instance().forceUpdate()

ERROR:

// when doing a snapshot
expect(received).toEqual(expected) // deep equality

Solution:

check what you are providing the snapshot... might be too much or the wrong info

ERROR:

Jest encountered an unexpected token
This usually means that you are trying to import a file which Jest cannot parse, e.g. it's not plain JavaScript.
By default, if Jest sees a Babel config, it will use that to transform your files, ignoring "node_modules".

 SyntaxError: /Users/matthewmalone/Documents/turing/mod_3/projects/cnsquidmountain/cnsquidmountain/src/containers/Round/round.test.js: Unexpected token (645:0)

     643 | //     expect(fetchWord).toHaveBeenCalled()
     644 | //   })
   > 645 | })
         | ^ (edited) 

Solution:

Delete brackets

Coding

ERROR:

FAILED TO COMPILE: Expected an assingment or function call and instead saw an expression

// BAD
export const mapStateToProps = state => {
  details: state.id
}

Solution:

// GOOD - needs to return and implicit object
export const mapStateToProps = state => ({
  details: state.id
})

ERROR:

mapDispatchToProps() in Connect(App) must return a plain object. Instead recieved undefined

// BAD
export const mapDispatchToProps = dispatch => {
  bindActionCreators
  ({
    setDetails,
    hasErrored
  }, dispatch)
}

Solution:

// GOOOOOD - take out extra curly brackets - it needs to return bindActionCreators function
export const mapDispatchToProps = dispatch => bindActionCreators
  ({
    setDetails,
    hasErrored
  }, dispatch)

ERROR:

Invariant Violation: Could not find "store" in the context of "Connect(ResultsCard)". Either wrap the root component in a <Provider>, or pass a custom React context provider to <Provider> and the corresponding React context consumer to Connect(ResultsCard) in connect options.

Solution:

when i have gotten this error it has been because I added in mapstateto props to a component and forgot to deconstruct it in my test file from `Component` to `{Component, mapStateToProps, etc...}`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment