Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fatal error causes Mocha to exit #735

Closed
itsjamie opened this issue Jan 23, 2013 · 2 comments
Closed

Fatal error causes Mocha to exit #735

itsjamie opened this issue Jan 23, 2013 · 2 comments

Comments

@itsjamie
Copy link

Hello! With the recent release of PhantomJS 1.8 I have started to add on front-end testing to my existing tests with Mocha. However, I am running into an issue with errors causing exits.

Running the tests below, I would expect something like..

x should fail
check should pass

1 of 2 tests failed:

  1. reason it failed.

Actual Output

Running "simplemocha:frontend" (simplemocha) task
=============
webdriver load
=============

Load Google
Fatal error: expected 'Google' to equal 'Github'

Back on command prompt.

To run the tests, I am using the grunt task simple-mocha via this configuration...

timeout: 5000,
ignoreLeaks: false,
ui: 'bdd',
reporter: 'spec'

The test itself boils down to...

module.exports = function() {
    var chai = require('chai'),
        should = chai.should(),
        wd = require("selenium-webdriverjs"),
        client;

    describe('Loading google...', function() {
        beforeEach(function() {
            client = new wd.Builder().
                usingServer('http://localhost:10000').
                withCapabilities({
                    'browserName': 'phantomjs',
                    'platform': 'ANY',
                    'version': '',
                    'javascriptEnabled': true
                }).
                build();
        })

        afterEach(function() {
            client.quit();
        })

        it('should fail', function(done) {
            client.get('http://github.com');
            client.getTitle().then(function(title) {
                title.should.equal('Google');
                done();
            });
        })

        it('should pass', function(done) {
            client.get('http://google.com')
            client.getTitle().then(function(title) {
                title.should.equal('Google');
                done();
            })
        })

    });
}();

I have been able to get the behaviour I want by wrapping the async call at getTitle with a try/catch, like so..

try {
    title.should.equal('Google');
    done();
} catch(e) {
    done(e);
}

However, I don't believe you are intended to need to do this.

@itsjamie
Copy link
Author

I believe this is because I am using the grunt task simple-mocha. If I run using mocha from the command line, this works as expected.

@itsjamie
Copy link
Author

Example

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant