简体   繁体   English

在带有节点NOT io.js的Mocha测试中使用jQuery

[英]Using jQuery in Mocha tests with Node NOT io.js

I'm running Mocha/Chai unit tests of a module which uses jQuery (for ajax calls) and of course jQuery complains about the missing document, cause I run tests without browser. 我正在运行使用jQuery(用于ajax调用)的模块的Mocha / Chai单元测试,当然jQuery抱怨缺少文档,因为我在没有浏览器的情况下运行测试。 I found jsdom module which creates virtual dom, that can fool jquery, but the project has ditched node.js in favor of io.js and can't be used with node. 我发现创建虚拟dom的jsdom模块可以欺骗jquery,但该项目放弃了node.js,转而使用io.js,并且不能与node一起使用。 I don't think I feel like switching to io.js in the middle of a project so my question is: 我不认为我想在项目中间切换到io.js,所以我的问题是:

Is there any sane way of using jQuery in Mocha tests from commandline at the moment? 目前有没有在命令行中在Mocha测试中使用jQuery的明智方法?

Node can make its own HTTP requests with a built-in http module. 节点可以使用内置的http模块发出自己的HTTP请求。 You don't need jQuery. 您不需要jQuery。 There is also the request module which is very nice and probably quite a few others. 还有一个request模块,它非常好,可能还有很多其他模块。

Your options are: 您的选择是:

  1. Don't use jQuery 不要使用jQuery
  2. Switch to iojs anyway (or node 4 ) 无论如何都要切换到iojs(或node 4
  3. Install an older version (earlier than version 4) of jsdom that will still allow you to use older versions of node 安装jsdom的旧版本(版本4之前),仍将允许您使用旧版本的node

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM