node.js - 我在哪里写这个 mocha-zombie node.js 测试失败了?

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

我正在尝试设置一个新的 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);
            });
        });
   });
});

最佳答案

您忘记了 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);
        });
    });
  });
});

关于node.js - 我在哪里写这个 mocha-zombie node.js 测试失败了?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13253083/

相关文章:

reactjs - 不变违规 : Could not find "store" in either the context or props of "Connect(SportsDatabase)"

node.js - npm 运行脚本 : node server. js && Mocha 测试

node.js - 使用 mocha/superagent 测试本地 https 服务器

vb.net - 从 VB.NET 与 node.js 通信

node.js - webpack-cli 未知参数 : --output

java - 对于 Sikulix,Mac 上的 App.close() 关闭应用程序,但返回 false。它是否正确?

python - 如何模拟我的函数之一的输出以进行单元测试?

node.js - 为什么我的 jwt token 在背面而不是正面返回 null

javascript - 将模板引擎加载到node.js/express中

testing - Maven 测试在安装阶段失败但在测试阶段没问题