samedi 28 mars 2015

Why is PhantomJS behaving different than Chromium for testing?

The last days I've been using PhantomJS 1.9.8 to test AngularJS 1.3.15 code. Today it is driving me nuts giving me errors that I can't reproduce on Chromium.


First issue is with the current property of $route. On a controller I have something similar to this:



...
.controller('HomeCtrl', [ '$route', function ($route) {
console.log($route.current);
}
...


The above will print undefined with PhantomJS but it will print the correct object with Chromium.


PhantomJS Output



LOG: 'Running! :)'
LOG: undefined


Chromium's output


prints object to console


Second issue is with $scope. To check that the previous problem is not caused by a bad handled asynchronous call (as mentioned here), I've tried to set a listener with $scope.$on:



...
.controller('HomeCtrl', [ '$scope', '$route', function ($scope, $route) {
console.log($route.current);

$scope.$on('$routeChangeSuccess', function() {
console.log($route.current);
});
}
...


PhantomJS won't recognize $scopeProvider while Chromium does.


PhantomJS Output



LOG: 'Running! :)'
PhantomJS 1.9.8 (Linux) Controller: HomeCtrl should do something FAILED
Error: [$injector:unpr] Unknown provider: $scopeProvider <- $scope <- HomeCtrl


Chromium's output


prints the same object two times to console


NOTE: I ran both applications under the same grunt task which means both were running almost at the same time.


For testing I'm using Karma v0.12.32 and Jasmine v2.2.0. Here is the unit test for the controller:



describe('Controller: HomeCtrl', function () {
beforeEach(module('app'));
var $controller;
beforeEach(inject(function (_$controller_) {
$controller = _$controller_('HomeCtrl');
}));

it('should do something', function () {
expect($controller.fake).not.toBeDefined();
});
});


For me, this doesn't make any sense taking into consideration both are WebKit based and the results are extremely different technically. Please, correct me if I'm missing something on the code.


Why is this happening? Is it possible to get PhantomJS working so I don't need manual testing?


Aucun commentaire:

Enregistrer un commentaire