wardbell / bardjs

Spec helpers for testing angular v.1.x apps with Mocha, Jasmine and QUnit
MIT License
178 stars 34 forks source link

Unable to test using PhantomJS #34

Closed mikeerickson closed 8 years ago

mikeerickson commented 8 years ago

So, the following section of code is failing when using PhantomJS (with Karma) works fine with Chrome

beforeEach(function() {
    bard.appModule('app');
    bard.inject(this, '$controller', '$httpBackend', '$log', '$q', '$rootScope', 'dataservice', 'peopleService');
  });

I know all is loaded correctly (through karma.config.js) as the Chrome browser option is working just fine

The error in console is...

 "before each" hook for "should pass"
      PhantomJS 1.9.8 (Mac OS X 0.0.0)
    Error: [$injector:modulerr] Failed to instantiate module ng due to:
    TypeError: 'null' is not an object (evaluating 'this')
attilacsanyi commented 8 years ago

Afaik the solution for this was to update two packages in the package.json:

  1. Use phantomjs2 launcher
  2. Use new phantomjs lib

"karma": "v0.13.19", "karma-phantomjs2-launcher": "v0.5.0", "phantomjs-prebuilt": "v2.1.4"

Hope this helps.

What is your opinion @wardbell,thx.

mikeerickson commented 8 years ago

@attilacsanyi Thanks for offer, but still doesnt work. Are you using phantom globally?

21 02 2016 11:40:36.518:WARN [launcher]: Can not load "PhantomJS", it is not registered!
  Perhaps you are missing some plugin?

Also, I am to assume I should (and did) remove

"karma-phantomjs-launcher": "^0.2.1",
$ npm i -D phantomjs-prebuilt@2.1.4

or

$ npm i -g phantomjs-prebuilt@2.1.4
mikeerickson commented 8 years ago

@attilacsanyi Ah, pilot error.

Also had to make this change in karma.conf.js

browsers: ['Chrome','PhantomJS'],    

to

browsers: ['Chrome','PhantomJS2'],  // had to change to PhantomJS2
mikeerickson commented 8 years ago

Whoops, I forgot to close this ticket....

@attilacsanyi Thanks again for your assistance.

attilacsanyi commented 8 years ago

Yes forgot to mention karma config with PantomJS2. I used dev dependencies only. Good to see its working for you. Yor welcome.

enterpriseSoftware commented 8 years ago

this still isn't working for me done all of the above and still get the same error. { "name": "movie-app", "version": "1.0.0", "description": "learning unit tsting", "main": "index.js", "scripts": { "test": "node_modules/karma/bin/karma start karma.conf.js" }, "author": "", "license": "ISC", "devDependencies": { "jasmine": "^2.4.1", "karma": "^0.13.22", "karma-chrome-launcher": "^0.2.3", "karma-firefox-launcher": "^0.1.7", "karma-jasmine": "^0.3.8", "karma-phantomjs2-launcher": "v0.5.0", "phantomjs-prebuilt": "^2.1.4" }, "dependencies": { "angular": "^1.5.5", "angular-mocks": "^1.5.5" } }