第二个测试表明 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
最佳答案
这里没有 Mocha 专家,但是应该存在看起来只是证明从jquery选择器返回的结果存在,而且它们确实存在,它们只是空的。即使该示例无法正常工作,您也可以根据 jquery 选择器将任何内容放入它们的“应该存在”中,并且它会返回“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)
关于javascript - Mocha 通过了应该失败的测试 (ember-mocha-adapter),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24252936/