PhantomJS “Can't find variable: require” when using PhantomJasmine

…衆ロ難τιáo~ 提交于 2019-12-08 17:05:47

问题


I would like to use Phantomjs and Jasmine for unit testing javascript. Phantomjs's website recommends that I use a separate thing to handle this, specifically, PhantomJasmine. I downloaded PhantomJasmine and ran the example. Everything went perfectly. I then added the line var system = require('system'); to the top of example_spec.js. The Phantomjs now throws an error when I try to run the example I get "ReferenceError: Can't find variable: require". So, I want to do need things like launch the browser, but it looks like I cannot combine jasmine AND phantomjs syntax. I can only run pure jasmin using Phantomjs. How can I use both in the same file? like:

console.log('Loading a web page');
var page = new WebPage();
var url = "http://www.phantomjs.org/";
page.open(url, function (status) {
    //Page is loaded!
    describe("A suite", function() {
      it("contains spec with an expectation", function() {
        expect(true).toBe(true);
      });
    });
    phantom.exit();
});

回答1:


It's not quite how you should be using it. The code to control phantomjs shouldn't be muddied with jasmine specs and vice versa.

You should separate your specs into .js files and create a standard jasmine setup with an HTML spec runner which loads the spec .js files and open that HTML file in phantomjs.

Another solution is to use grunt with phantomjs and jasmine to have automatically run jasmine specs.

https://github.com/cowboy/grunt
https://github.com/creynders/grunt-jasmine-task



来源:https://stackoverflow.com/questions/11891998/phantomjs-cant-find-variable-require-when-using-phantomjasmine

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!