摩卡通过应该失败的测试(ember-mocha-adapter)

时间:2014-06-16 22:01:36

标签: javascript ember.js coffeescript mocha chai

第二个测试,说h3元素存在,应该明显失败,但不是。发生了什么事?

使用Mocha,Chai,Ember和ember-mocha-adapter,我创建了这个简单的例子: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();


我的JSFiddle:http://jsfiddle.net/signer247/UD2D3/4/

我从这个例子构建了我的JSFiddle:http://jsfiddle.net/UD2D3/1/

这是ember-mocha-adapter:https://github.com/teddyzeenny/ember-mocha-adapter

1 个答案:

答案 0 :(得分:2)

这里没有mocha专家,但是应该存在看起来它只是证明从jquery选择器返回的结果存在,并且它们确实存在,它们只是空的。即使该示例无法正常工作,您也可以根据jquery选择器将任何内容放入其应存在的内容并返回传递。

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/

相关问题