Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

Function.prototype.bind.apply(...) is not a constructor #14814

Closed
kiro112 opened this issue Jun 22, 2016 · 2 comments
Closed

Function.prototype.bind.apply(...) is not a constructor #14814

kiro112 opened this issue Jun 22, 2016 · 2 comments

Comments

@kiro112
Copy link

kiro112 commented Jun 22, 2016

Im trying to learn angular-tdd

with this versions my tests is working fine
depencies version
angular: 1.4.8
angular-mocks: 1.4.8
node: v4.4.5
karma-cli: 0.13.22

but when i use
versions
"angular": "^1.5.7"
"angular-mocks": "^1.5.7"

it throws an error

karma start karma.conf.js

22 06 2016 16:53:04.002:WARN [karma]: No captured browser, open http://localhost:9876/
22 06 2016 16:53:04.012:INFO [karma]: Karma v0.13.22 server started at http://localhost:9876/
22 06 2016 16:53:04.018:INFO [launcher]: Starting browser Chrome
22 06 2016 16:53:05.959:INFO [Chrome 51.0.2704 (Linux 0.0.0)]: Connected on socket /#Vfy_Fpt6BZ2INRyEAAAA with id 36097936
Chrome 51.0.2704 (Linux 0.0.0) calculator sum 1 + 1 should equal 2 FAILED
    TypeError: Function.prototype.bind.apply(...) is not a constructor
        at Object.instantiate (/home/malanay/workspace/AngularJs-BDD-101/node_modules/angular/angular.min.js:41:477)
        at /home/kiro112/workspace/AngularJs-BDD-101/node_modules/angular/angular.min.js:90:3
        at /home/kiro112/workspace/AngularJs-BDD-101/node_modules/angular-mocks/angular-mocks.js:2214:12
        at Object.it (/home/kiro112/workspace/AngularJs-BDD-101/tests/calculator.controller.test.js:17:21)
Chrome 51.0.2704 (Linux 0.0.0): Executed 1 of 1 (1 FAILED) (0 secs / 0.027 Chrome 51.0.2704 (Linux 0.0.0): Executed 1 of 1 (1 FAILED) ERROR (0.037 secs / 0.027 secs)
@wesleycho
Copy link
Contributor

The problem is using the fat arrow syntax to define the function constructor for the controller class. Assuming your function passed as the second argument to module.controller is Foo, Angular will call new Foo(...) on it, which is illegal with the fat arrow syntax in ES6.

@gkalpak
Copy link
Member

gkalpak commented Jun 23, 2016

@wesleycho, is right. Controllers should be instantiable (i.e. called with new), so things like arrow functions (() => {...}) and shorthand object methods ({someMethod() {...}}) aren't suitable for controllers.

See #14766 (comment) for more details.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants