gpt4 book ai didi

node.js - Mocha、CoffeeScript、Zombies JS、超时?

转载 作者:太空宇宙 更新时间:2023-11-03 23:10:56 24 4
gpt4 key购买 nike

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

我使用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 毫秒的超时,它挂起几秒钟然后失败。我尝试四处寻找,但似乎没有任何记录这个问题,或者也许这是我自己的错。我几个小时前才开始学习 CoffeeScript 。

最佳答案

行后:

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

调用方法:

done()

这样做会向 mocha 发出测试已完成的信号。由于 Node.js 平台上编写的大多数代码都具有异步性质,因此这种情况一定会发生。

关于node.js - Mocha、CoffeeScript、Zombies JS、超时?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11557512/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com