2

The second test, saying that an h3 element exists, should clearly fail, but doesn't. What's going on?

Using Mocha, Chai, Ember, and ember-mocha-adapter, I created this simple example: http://jsfiddle.net/signer247/UD2D3/4/.


HTML

<div id="mocha"></div>
<hr/>
<div id="ember-testing"></div>

<script type="text/x-handlebars" data-template-name="application">

    <h1>Ember.js Testing with Ember Mocha Adapter</h1>

</script>


CoffeeScript

App = Em.Application.create()

App.Router.map ->
    @route 'index', path: '/'

App.rootElement = '#ember-testing';
App.setupForTesting()
App.injectTestHelpers()

Ember.Test.adapter = Ember.Test.MochaAdapter.create()

chai.should()

describe 'Changing a site via visit in the test with andThen helper', ->

    beforeEach ->
        App.reset()
        visit('/')

    it 'should work', ->
        andThen ->
            $c = $(App.rootElement)
            $c.find('h1').should.exist

    it 'should fail', ->
        andThen ->
            $c = $(App.rootElement)
            $c.find('h3').should.exist

$(document).ready ->
    mocha.run();


My JSFiddle: http://jsfiddle.net/signer247/UD2D3/4/

I built my JSFiddle off of this example: http://jsfiddle.net/UD2D3/1/

This is the ember-mocha-adapter: https://github.com/teddyzeenny/ember-mocha-adapter

4

1 回答 1

2

No mocha expert here, but should exists looks like it's just proving that the results returned from the jquery selector exist, and they do, they are just empty. Even the example doesn't work properly, you can put anything into their should exists based off the jquery selector and it returns passed.

it 'should work', ->
    andThen ->
        $c = $(App.rootElement)
        $c.find('h1').length.should.equal(1)

it 'should fail', ->
    andThen ->
        $c = $(App.rootElement)
        console.log($c.find('h3'));
        $c.find('h3').length.should.equal(1)

http://jsfiddle.net/3AQUN/

于 2014-06-16T22:08:05.943 回答