小编jnd*_*dcn的帖子

僵尸可以测试一个元素不存在吗?

我正在尝试在快速应用程序上使用zombie.js(使用mocha)以确保某些元素不会显示在页面上.这是我尝试这样做的方式:

var app = require('../app).app, // this is express but you don't care
    chai = require('chai'),
    should = chai.should(),
    Browser = require('zombie'),
    browser = new Browser();

describe("page", function() {

    it('should not have a the whatever element', function(done) {
        browser.visit('http://localhost:3000', function() {
            browser.query('#whatever').should.not.exist;
            done();
        });
    });

});
Run Code Online (Sandbox Code Playgroud)

现在,当我运行此测试时,它总是失败:

  • 如果#whatever存在,我得到这个:

    expected <div class="whatever">whatever</div> to not exist

  • 如果#whatever不存在,我希望测试通过,但我也得到一个错误

    TypeError: Cannot read property 'should' of null

也许这是一个愚蠢的测试,但有没有办法进行这样的测试,以使其通过?我哪里做错了?

谢谢.

mocha.js node.js express zombie.js chai

3
推荐指数
1
解决办法
1504
查看次数

标签 统计

chai ×1

express ×1

mocha.js ×1

node.js ×1

zombie.js ×1