i'm trying to test a piece of asynchronous code but sadly enough i'm getting an obscure error code and i cant seem to figure out what the issue is. The test runs fine in the browser but running it in phantomjs results in:
Uncaught Script error. (:0)
The test is written as an requirejs module and has a dependency on another module. Like i said this works fine in the browser, and when doing none async tests everything works fine in phantomjs as well. I'm using phantomjs 1.9.12 and mocha-phantomjs 3.4.1.
define([ "csl" ], function( csl )
{
describe( "CSL", function()
{
it( "isLoggedIn", function( testCompleted )
{
csl.isLoggedIn().then( function( partner )
{
chai.expect( partner ).to.be.a( "object" );
testCompleted();
} )
.fail( function( error )
{
testCompleted( error );
} );
} );
} );
} );
That is the error that mocha produces when there is an exception in an async function, and chai.expect can throw an AssertionError.
You can reproduce the same error in a browser with a simple timeout:
To fix it, you need to report the error via the callback rather than exceptions:
The problem isn't with phantom itself (other than whatever is making the test fail) but the connection between the test runner and phantom makes everything asynchronous, triggering the mocha bug.