第二个测试,即h3元素存在,显然应该失败,但没有。发生了什么?
使用摩卡、柴、恩伯和恩伯-摩卡适配器,我创建了一个简单的例子: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/
这是成员-摩卡适配器:https://github.com/teddyzeenny/ember-mocha-adapter。
发布于 2014-06-16 22:08:05
这里没有摩卡专家,但应该存在,这只是证明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/
https://stackoverflow.com/questions/24252936
复制相似问题