0
我使用zombiejs +摩卡編寫操縱的DOM庫的一些測試中,它使用JavaScript原生功能,如使用document.createElement(),我的問題是,當我運行測試我得到一個異常說'文檔沒有定義'。摩卡+ ZombieJs,文件沒有規定
是它zombiejs問題或與jsDOM?我該如何解決它?
這裏是我的代碼示例:
HTML:
<!DOCTYPE html>
<html>
<head>
<script src="mocha.js"></script>
<script src="expect.js"></script>
<title>XS UI Tests</title>
<script type="text/javascript" charset="utf-8" src="../lib/mylibrary.js"></script>
<script>
mocha.setup('bdd');
</script>
</head>
<body>
<div id="table"></div>
<div id="controls"></div>
<div id="form"></div>
<div id="mocha"></div>
<script src="tests.js"></script>
</body>
</html>
在tests.js :
var expect = require('expect.js')
, Zombie = require('zombie' )
, browser = new Zombie({ debug: true })
;
describe('XS UI Tests:', function() {
before(function(done) {
browser.visit('http://localhost:8080/test/ui.html', done);
});
it('expect ui.html to be loaded', function() {
expect(browser.success).to.be(true);
});
describe('Table Tests:', function() {
it('expect div#table (table container) to exist', function() {
expect(browser.query("#table")).to.be.ok();
});
});
});
謝謝您的幫助
非常感謝您的回答。 確實我在我的測試腳本中通過'require'加載我的庫。 我只是修改我的代碼來加載我直接在HTML中測試的庫,但它不加載! – Khalifa 2013-05-20 18:01:10
@Khalifa確保它在瀏覽器中,然後嘗試加入一些調試語句殭屍API,特別是在[資源](https://github.com/assaf/zombie/blob/master/src/zombie/resources .coffee)對象。 – gcochard 2013-05-21 02:00:33
在瀏覽器中工作,沒問題,我已經在我的庫中調試消息,似乎我的庫不加載! – Khalifa 2013-05-21 17:27:41