【问题标题】:Where am I failing in writing this mocha-zombie node.js test?我在哪里写这个 mocha-zombie node.js 测试失败了?
【发布时间】:2012-11-06 23:49:30
【问题描述】:

我正在尝试设置一个新的 node.js 项目(带有 express 的东西)。但在我得到任何东西之前,我想设置测试。由于我对使用 node.js 的 TDD 完全陌生,因此我无法设置它。

谁能告诉我为什么这个小测试通过了?不管我是否输入正确的 URL 都没有关系。就这么过去了。

var assert=require('assert');
var Browser = require("zombie");
var browser = new Browser();
describe('Home page', function () {
   describe ('title', function () {
        it ('should have a title', function () {
            browser.visit ("http://no-such-site.com/").
            then(function (){
                assert.equal(browser.text("title"), "Whatever goes here");
            }).
            fail(function(err) {
                console.log("Failed with error: ", error);
            });
        });
   });
});

【问题讨论】:

    标签: node.js testing mocha.js zombie.js


    【解决方案1】:

    您忘记了 it 函数的 done 参数。

    var assert=require('assert');
    var Browser = require("zombie");
    var browser = new Browser();
    describe('Home page', function () {
      describe ('title', function () {
        it ('should have a title', function (done) {
            browser.visit ("http://no-such-site.com/").
            then(function (){
                assert.equal(browser.text("title"), "Whatever goes here");
                done(); 
            }).
            fail(function(err) {
                console.log("Failed with error: ", error);
                done(err);
            });
        });
      });
    });
    

    【讨论】:

    • 仍然通过测试。我什至在测试中添加了 kljvfrhw() 调用,它仍然有效。
    • 好吧,它没有,我忘了在它的函数的第二个参数参数中添加(完成):)
    猜你喜欢
    • 2017-03-23
    • 1970-01-01
    • 2012-02-06
    • 2012-10-10
    • 1970-01-01
    • 1970-01-01
    • 2014-08-06
    • 2014-11-22
    • 2019-04-17
    相关资源
    最近更新 更多