首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >摩卡通过了应该失败的测试(成员-摩卡-适配器)

摩卡通过了应该失败的测试(成员-摩卡-适配器)
EN

Stack Overflow用户
提问于 2014-06-16 22:01:36
回答 1查看 202关注 0票数 2

第二个测试,即h3元素存在,显然应该失败,但没有。发生了什么?

使用摩卡、柴、恩伯和恩伯-摩卡适配器,我创建了一个简单的例子:http://jsfiddle.net/signer247/UD2D3/4/

HTML

代码语言:javascript
复制
<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

代码语言:javascript
复制
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/

这是成员-摩卡适配器:https://github.com/teddyzeenny/ember-mocha-adapter

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-06-16 22:08:05

这里没有摩卡专家,但应该存在,这只是证明jquery选择器返回的结果是存在的,而且它们都是空的。即使该示例不能正常工作,您也可以基于jquery选择器将任何内容放入它们的应存在中,并将其返回传递。

代码语言:javascript
复制
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/

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/24252936

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档