nathanboktae / mocha-phantomjs

:coffee: :ghost: Run client-side mocha tests in the command line through phantomjs
MIT License
954 stars 112 forks source link

including mocha.js in mocha-phantom script #213

Closed bmark1111 closed 9 years ago

bmark1111 commented 9 years ago

I have the following mocha-phantomjs script:

var chai = require("vendor/chai"); var mocha = require('vendor/mocha'); mocha.ui('bdd'); mocha.reporter('html'); var expect = chai.expect;

describe("Simple", function() { describe("constructor", function() { it("a simple test", function() { var test = 1 + 1; expect(test).to.equal(2); phantom.exit(); }); }); });

I keep getting the following error when running this from the command line:

mocha-phantomjs phantomtest.js

mocha was not initialized before the page finished loading. Make sure to include mocha.js as a direct script and call mocha.ui or mocha.setup.

What am I doing wrong.

Thanks for your help

nathanboktae commented 9 years ago

You need to provide a reference to an HTML file. This is not node or phantomjs code here.... Please read the readme carefully and see the examples. On Oct 14, 2015 10:35 AM, "bmark1111" notifications@github.com wrote:

I have the following mocha-phantomjs script:

var chai = require("vendor/chai"); var mocha = require('vendor/mocha'); mocha.ui('bdd'); mocha.reporter('html'); var expect = chai.expect;

describe("Simple", function() { describe("constructor", function() { it("a simple test", function() { var test = 1 + 1; expect(test).to.equal(2); phantom.exit(); }); }); });

I keep getting the following error when running this from the command line:

mocha-phantomjs phantomtest.js

mocha was not initialized before the page finished loading. Make sure to include mocha.js as a direct script and call mocha.ui or mocha.setup.

What am I doing wrong.

Thanks for your help

— Reply to this email directly or view it on GitHub https://github.com/nathanboktae/mocha-phantomjs/issues/213.

bmark1111 commented 9 years ago

Oh I see. I'm new to mocha-phantomjs so if you could just bear with me. When I run with my html test runner I get this error:

mocha-phantomjs v1.html

Error loading resource file:.............................. Details: Request for opening non-local file file:...............

bmark1111 commented 9 years ago

Read through all the examples and README. Sorry but still cant see an answer to my issue.

nathanboktae commented 9 years ago

Dobyour tests run when you open v1.html in a browser?

bmark1111 commented 9 years ago

yes they run fine

nathanboktae commented 9 years ago

Resources errors don't necessarily mean your tests failed, and you'd see the same output in the console as you do in a browser. I can't really tell exactly from the information you provided.

DexSinis commented 9 years ago

Likely due to external resource loading and timing, your tests require calling window.initMochaPhantomJS() before calling any mocha setup functions. See https://github.com/nathanboktae/mocha-phantomjs/issues/213

how can i fix this problem

nathanboktae commented 9 years ago

Ah, the issue is actually nathanboktae/mocha-phantomjs-core#12, sorry about that.

But do what it says and call window.initMochaPhantomJS() before calling mocha.setup or other setup functions

window.initMochaPhantomJS && window.initMochaPhantomJS()
mocha.setup('bdd') // or whatever, mocha.ui('tdd'), mocha.slow(), etc etc...
nathanboktae commented 9 years ago

closing since this is a clarification thread.