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

undefined is not a function (evaluating 'this.routes.find(...)') #251

Closed
jordan-enev opened this issue Jan 24, 2018 · 6 comments
Closed

undefined is not a function (evaluating 'this.routes.find(...)') #251

jordan-enev opened this issue Jan 24, 2018 · 6 comments
Labels

Comments

@jordan-enev
Copy link

@jordan-enev jordan-enev commented Jan 24, 2018

Unit testing stack (I'm using react-redux-starter-kit):

  • karma 2.0.0
  • karma-phantomjs-launcher 1.0.4
  • phantomjs-prebuilt - 2.1.16
  • mocha & chai & sinon

Here is the mock:

fetchMock.post('*', { url: 'https://example.com/' })

When I run the tests, they failed with the following error stack:

FAILED TESTS:
  (Actions) Api
    ✖ Fetches `API_URL`
      PhantomJS 2.1.1 (Linux 0.0.0)
    undefined is not a function (evaluating 'this.routes.find(function (route) {
    		return route.matcher(url, opts);
    	})')
    router@webpack:///~/fetch-mock/es5/lib/fetch-handler.js:128:0 <- tests/test-bundler.js:121000:30
    executeRouter@webpack:///~/fetch-mock/es5/lib/fetch-handler.js:47:0 <- tests/test-bundler.js:120919:28
    fetchHandler@webpack:///~/fetch-mock/es5/lib/fetch-handler.js:20:0 <- tests/test-bundler.js:120892:35
    [native code]
    webpack:///src/utils/api.js:107:0 <- tests/test-bundler.js:37061:17
    fetch@webpack:///src/utils/api.js:86:0 <- tests/test-bundler.js:37032:26
    post@webpack:///src/utils/api.js:117:0 <- tests/test-bundler.js:37073:21
    post@webpack:///src/redux/middlewares/enhancedThunk.js:22:0 <- tests/test-bundler.js:90178:40
    webpack:///src/redux/actions/api.js:31:0 <- tests/test-bundler.js:36597:20
    webpack:///~/redux-thunk/lib/index.js:11:0 <- tests/test-bundler.js:84607:24
    webpack:///tests/redux/actions/api.spec.js:42:0 <- tests/test-bundler.js:95058:26
@jordan-enev

This comment has been minimized.

Copy link
Author

@jordan-enev jordan-enev commented Jan 24, 2018

I found out that the problem is that find method is undefined, independently of the fact that I'm using babel-preset-env.

It looks like there is a Babel runtime problem with an instance methods.

The solution is to include babel-polyfill once in your testing bootstrap file, and set Babel useBuiltIns option.

Do you think it's worth to mention in the docs, or I'm doing it wrong?

@wheresrhys

This comment has been minimized.

Copy link
Owner

@wheresrhys wheresrhys commented Jan 27, 2018

Yeah, I'll add it to the troubleshooting guide. Thanks for raising it.

@wheresrhys

This comment has been minimized.

Copy link
Owner

@wheresrhys wheresrhys commented Feb 3, 2018

Could you try with 6.1.0-beta.1 please

@wheresrhys

This comment has been minimized.

Copy link
Owner

@wheresrhys wheresrhys commented Mar 11, 2018

Can you try v6.1.0-beta.2 please. Finally managed to get a new release out

@jordan-enev

This comment has been minimized.

Copy link
Author

@jordan-enev jordan-enev commented Mar 12, 2018

I've tested it just right now and everything's fine! Thank you :)

@wheresrhys

This comment has been minimized.

Copy link
Owner

@wheresrhys wheresrhys commented Mar 12, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.