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

Arrow functions not working in Chrome 50 with ngMock inject #14487

Closed
mribichich opened this issue Apr 21, 2016 · 7 comments
Closed

Arrow functions not working in Chrome 50 with ngMock inject #14487

mribichich opened this issue Apr 21, 2016 · 7 comments

Comments

@mribichich
Copy link

mribichich commented Apr 21, 2016

Hi there, before the Chrome 50 update arrow functions were working for me, but suddenly karma started to failed. The message is something with the Injector.

I dont know if arrow functions were intended to work or not, but they dont work anymore.

This used to work with Chrome 49.x:

 beforeEach(inject((_$controller_) => {
        $controller = _$controller_;
    }));

I solved it using function:

 beforeEach(inject(function(_$controller_) {
        $controller = _$controller_;
    }));

Here's the error message, its very easy to reproduce:

TypeError: Cannot read property '1' of null
            at Function.annotate (/bower_components/angular/angular.js:3907:24)
            at Function.angular.injector.$$annotate (/bower_components/angular-mocks/angular-mocks.js:2583:36)
            at injectionArgs (/bower_components/angular/angular.js:4626:36)
            at Object.invoke (/bower_components/angular/angular.js:4657:18)
            at Object.workFn (/bower_components/angular-mocks/angular-mocks.js:2810:20)
@Narretz
Copy link
Contributor

Narretz commented Apr 21, 2016

Which version of angular do you use?
And do you use fat arrows in your application code, too?
This seems to be a karma specific problem, because I've just run our tests on Version 50.0.2661.75 beta-m (64-bit) and there are no failures.

@mribichich
Copy link
Author

Sorry I should have wrote that. I used Angular 1.5 and then test it with
1.5.5

I really don't know if its karma or angular or even jasmine, but everything
starting to failed as soon as my CI updated to Chrome 50.

The same thing happened to me, in my dev machine. While I was running on
Chrome 49 I had no problem, in fact I didn't even know why it was failing
on the CI, and it was driving me crazy, and the minute I updated my dev
machine to Chrome 50, they starting failing. And changing the arrows to
functions, solved the problem.

I didn't change karma, jasmine nor angular version. The only thing I end up
changing was Chrome to see it failed.

On Thu, Apr 21, 2016 at 10:53 AM Martin Staffa notifications@github.com
wrote:

Which version of angular do you use?
This seems to be a karma specific problem, because I've just run our tests
on Version 50.0.2661.75 beta-m (64-bit) and there are no failures.


You are receiving this because you authored the thread.
Reply to this email directly or view it on GitHub
#14487 (comment)

@mribichich
Copy link
Author

I'm using Chrome 50.0.2661.75 m

@mribichich
Copy link
Author

The thing is this: I use TS. For my app the output is ES5, but for my tests I was using ES6 output. And they were running ok until two days ago.

Every project that had the tests output to ES6, for karma only, starting failing.

After a couple of hours I realized that the Chrome version was different. When I updated my dev machine the same happened.

I changed the output for karma tests to ES5, and everything starting working again.

Maybe something changed in chrome core, and angular got broken.

@Narretz
Copy link
Contributor

Narretz commented Apr 21, 2016

I can reproduce this. It must be because of the inject fn. But I don't know what changed in Chrome 50 that this doesn't work anymore.

@Narretz
Copy link
Contributor

Narretz commented Apr 21, 2016

It looks like the output of toString for fat arrow functions has changed

edit: but shouldn't that also affect regular usage? Weird.

@Narretz Narretz changed the title Arrow functions not working in Chrome 50 Arrow functions not working in Chrome 50 with ngMock inject Apr 21, 2016
@gkalpak
Copy link
Member

gkalpak commented Apr 22, 2016

This seems to be indeed a bug in Chrome. The problem happens in here, where we try to extract the arguments from the arrow function.

Although fnText seems correct, for some reason (bug?), calling .match(ARROW_ARG) on it returns null (although it does much the RegExp).
If you put a breakpoint in there and you manually create s string (say fnText2) identical to fnText, you can observe the following:

fnText2 === fnText         // Returns true
fnText2.match(ARROW_ARG)   // Returns an array
fnText.match(ARROW_ARG)    // Returns null (!?!)

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

Successfully merging a pull request may close this issue.

3 participants