lundi 30 janvier 2017

Unknown test failed case using mocha, zombie and chai

I'm trying cross-page test using mocha, zombie and chai, following instructions in Web Development with Node & Express.

version info: macOS 10.12.2, mocha 3.5.0, chai 3.2.0, zombie 5.0.5, node v7.4.0.

QA JS Code:

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();
            })
        })
})

What shows in terminal(after 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)

What makes me confused: 1) I called done() in every test, but why test 1 still get time exceeded? 2) In test 3, there's no code related to link matching '.requestGroupRate', so where does it come?

Note: I've checked the localhost:3000\river page manually. There is a <a> with class of requestGroupRate. The coast page doesn't exist, so the test 2 is a must-fail test.




Aucun commentaire:

Enregistrer un commentaire