简体   繁体   中英

Testing ember js with mocha?

I'm using lineman with testem , ember , and mocha+chai .

I want to test ember . So far, because of how the test scripts and test pages are handled, I can visit a page and test it's contents.

The test page looks like

------------------------
Loop through mocha test cases

------------------------

Ember App View




------------------------

However, when I try to test for stuff outside of the content like page title:

describe('testing page title', function () {
    it('should equal ember-template', function () {
        visit('/');
        find('title').text().should.equal('ember-template');
        find('title').length; // this is 0
    });
});

it gives me an error of

✘ expected '' to equal 'ember-template'
    AssertionError: expected '' to equal 'ember-template'

How do I test ember completely with mocha ?

visit() is asynchronous, whereas find() is synchronous (it's just a jquery selection under the hood), so the transition to the page likely isn't finished by the time you check the title. The andThen() test helper will wait for the preceding async activity to finish before executing a callback. Try the following:

describe('testing page title', function () {
    it('should equal ember-template', function () {
        visit('/');
        andThen(function() {
            find('title').text().should.equal('ember-template');
            find('title').length; // this is 0
        });
    });
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM