Update PhantomJS to test Angular 1.5

TL;DR: npm install karma-phantomjs-launcher@latest phantomjs-prebuilt@latest

Updating an old project to Angular 1.5 all my tests broke or that’s what I thought when I got the Error: [$injector:modulerr] Failed to instantiate module ng due to: TypeError: ‘undefined’ is not an object (evaluating ‘Function.prototype.bind.apply’).

Doing a bit of research I found out the solution lies in updating to PhantomJS 2. But the karma-phantomjs-launcher package has now a dependency on phantomjs-prebuilt.

What? phantomjs-prebuilt happens to be a npm wrapper to make PhantomJS available to Node.js developers and until last month it was published as phantomjs, which caused confusion.

So removing our old dependency on phantomjs and installing the latest versions of launcher and wrapper we are good to go.

$ npm uninstall --save-dev phantomjs
$ npm install --save-dev karma-phantomjs-launcher@latest phantomjs-prebuilt@latest

Due to this, last Thursday I woke up wondering if people uses PhantomJS when unit testing AngularJS applications, because I’ve been using it as default ever since the beginning but with no particular reason other than the speed.

So I created a Twitter poll, fueled by the RT of my friend Todd Motto, where a 52% of the voters uses PhantomJS although a 25% still don’t unit test.

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s