【问题标题】:Mocha, CoffeeScript, ZombieJS, Timout?摩卡、咖啡脚本、僵尸、超时?
【发布时间】:2012-07-20 23:06:09
【问题描述】:

我遇到了一个奇怪的问题,我不知道为什么会这样。

我使用 express-coffeescript 作为框架,mocha 用于测试,以及 should、chai 和zombiejs 用于浏览器测试。

 request = require 'request'
 Browser = require 'zombie'
 assert  = require 'assert'
 chai    = require 'chai'  
 should  = require 'should'
 expect  = chai.expect
 chai.should

 browser = new Browser()

 describe 'GET /login', ->

    it 'should login a user successfully', (done) ->
        browser.on "error", -> 
             console.log "Error"

        browser.visit "http://localhost/test-laravel/public/login",  (browser),  ->

             browser.fill "username", "TheHydroImpulse"
             browser.fill "password", "SomePassword123"
             browser.pressButton "login", ->
                  console.log browser.location.pathname
                  should.equal "randomTextHere", "/test-laravel/public/dashboard"

这段代码运行良好,运行时测试当然失败

mocha test --compilers coffee:coffee-script -R spec

关于这个或问题的奇怪之处在于当我通过测试时。

should.equal "/test-laravel/public/dashboard", "/test-laravel/public/dashboard"

测试应该通过,但由于超时 2000 毫秒,它会挂起几秒钟而不是失败。我试着四处寻找,但似乎没有任何记录这个问题,或者这可能是我自己的错。几个小时前我才开始学习咖啡脚本。

【问题讨论】:

    标签: node.js timeout coffeescript mocha.js zombie.js


    【解决方案1】:

    行后:

    should.equal "/test-laravel/public/dashboard", "/test-laravel/public/dashboard"
    

    调用方法:

    done()
    

    执行此操作向 mocha 发出测试已完成的信号。这必须发生,因为在 Node.js 平台上编写的大多数代码都具有异步特性。

    【讨论】:

    • 一个简单的解决方案。谢谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-10-31
    • 2015-12-28
    • 2018-06-27
    • 2012-07-16
    • 1970-01-01
    • 2013-01-09
    • 2022-10-20
    相关资源
    最近更新 更多