簡體   English   中英

使用Mocha,Zombie和Chai的未知測試失敗案例

[英]Unknown test failed case using mocha, zombie and chai

我正在嘗試使用Mocha,zombie和chai進行跨頁測試,請按照“ 使用Node&Express進行Web開發”中的說明進行操作。

版本信息:macOS 10.12.2,mocha 3.5.0,chai 3.2.0,zombie 5.0.5,節點v7.4.0。

質量檢查JS代碼:

var Browser = require("zombie");
var assert = require("chai").assert;

var browser;

suite("Cross-Page Tests", function () {
    setup(function () {
        browser = new Browser();
    })
    // Test (1
    test("Requesting Group-Rate from the river page, should populate the referrer field", function (done) {
        var referrer = "http://localhost:3000/river";
        browser.visit(referrer, function () {
            browser.clickLink(".requestGroupRate", function () {
                assert(browser.field("referrer").value === referrer);
                done();
            })
        })
    })
    // Test (2
    test("Requesting Group-Rate from the coast page, should populate the referrer field", function (done) {
        var referrer = "http://localhost:3000/coast";
        browser.visit(referrer, function () {
            browser.clickLink(".requestGroupRate", function () {
                assert(browser.field("referrer").value === referrer);
                done();
            })
        })
    })
    // Test (3
    test("Visit request group rate page directly, should have an empty field.", function (done) {
            browser.visit("http://localhost:3000/request-group-rate", function () {
                assert(browser.field("referrer").value === "");
                done();
            })
        })
})

終端中顯示的內容 (在mocha -u tdd -R spec qa/tests-crosspage.js 2>/dev/null ):

...

  1) Cross-Page Tests Requesting Group-Rate from the river page, should populate the referrer field:
     Error: Timeout of 2000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves.


  2) Cross-Page Tests Requesting Group-Rate from the coast page, should populate the referrer field:
     Uncaught AssertionError: No link matching '.requestGroupRate'
      at Browser.clickLink (node_modules/zombie/lib/index.js:695:7)
      at qa/tests-crosspage.js:28:21
      at Browser.done (node_modules/zombie/lib/eventloop.js:589:11)
      at node_modules/zombie/lib/document.js:819:13
      at process._tickCallback (internal/process/next_tick.js:103:7)

  3) Cross-Page Tests Visit request group rate page directly, should have an empty field.:
     Uncaught AssertionError: No link matching '.requestGroupRate'
      at Browser.clickLink (node_modules/zombie/lib/index.js:695:7)
      at qa/tests-crosspage.js:18:21
      at EventLoop.done (node_modules/zombie/lib/eventloop.js:589:11)
      at Immediate.<anonymous> (node_modules/zombie/lib/eventloop.js:688:71)

是什么讓我感到困惑: 1)我在每個測試中都調用了done() ,但是為什么測試1仍然超出時間? 2)在測試3中,沒有與鏈接匹配'.requestGroupRate'相關的代碼,那么它從哪里來?

注意:我已經手動檢查了localhost:3000\\river頁面。 有一個<a>帶班的requestGroupRate 滑行頁面不存在,因此測試2是必須通過的測試。

https://github.com/EthanRBrown/web-development-with-node-and-express/issues/58

測試必須從

assert(browser.field('referrer').value === 'referrer');

assert(browser.field('referrer').value === ' ');

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM