nathanboktae / mocha-phantomjs

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

"'undefined' is not a function (evaluating 'mocha.ui('bdd')')" #243

Closed Nanofus closed 7 years ago

Nanofus commented 8 years ago

Hi! I'm trying to run some tests using the following HTML:

<html>
  <head>
    <meta charset="utf-8">
    <!-- encoding must be set for mocha's special characters to render properly -->
    <link rel="stylesheet" href="../node_modules/mocha/mocha.css" />
  </head>
  <body>
    <div id="mocha"></div>
    <script src="../node_modules/mocha/mocha.js"></script>
    <script src="../node_modules/chai/chai.js"></script>
    <script>
      mocha.ui('bdd')
      expect = chai.expects
    </script>
    <script src="../browserMqtt.js"></script>
    <script src="../main.js"></script>
    <script src="test.js"></script>
    <script>
      mocha.run()
    </script>
  </body>
</html>

I double-checked the file paths, they are all correct. If I console.log(mocha.ui) it returns the correct function. However, when I run mocha-phantomjs, I get the following error:

TypeError: 'undefined' is not a function (evaluating 'mocha.ui('bdd')')

I'm on Windows 10, phantomjs version is 2.1.1, mocha version is 2.4.5 and mocha-phantomjs version is 4.0.2.

Thanks in advance!

nathanboktae commented 8 years ago

Do the tests run in your browser?

Nanofus commented 8 years ago

Yes, they work fine in the browser.

eg-ops commented 7 years ago

Change the windows backslash (\) to unix slash (/) in the test runner file path. For example C:/dev/test/runner.html

nathanboktae commented 7 years ago

Closing without more information. mocha.ui('bdd') is used everywhere in the tests.

basherr commented 6 years ago

@Nanofus @nathanboktae The error seems to be fixed while using mocha-phantomjs -R dot "./tests/index.html" btw how does it work in the browser? C'z I'm getting ReferenceError: callPhantom is not defined at Context. (specs/abc.test.js:6:13)

describe('Screenshot', function() {
        it('takes screenshot', function() {
            var date = new Date()
            var filename = "/screenshot"
            console.log("Taking screenshot " + filename)
            callPhantom({'screenshot': filename})
      });
  });