问题标签 [nodeunit]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
0 回答
61 浏览

visual-studio - 使用 Visual Studio 2015 社区进行 Nodeunit 测试(已安装 NTVS)

我想知道是否有任何工具可以让我在 Visual Studio Community 2015 中测试和运行 nodeunit 测试(安装了 Node 工具)。我听说过 VsNodeTest,但它与 Visual Studio 2015 不兼容。我有什么工具或方法可以做到这一点吗?此外,测试在 typeScript 中。感谢您的帮助,路易斯

0 投票
1 回答
878 浏览

node.js - 如何断言nodeunit中的错误消息?

我正在尝试编写检查 nodeunit 中的错误消息的断言。如果错误消息与我的预期不符,我希望测试失败。但是,似乎不存在用于此的 API。这是我正在尝试做的事情:

foo.js

foo.test.js

如果错误消息不是“一些复杂的消息”,我想testFoo失败,但这不是它的工作方式。似乎“一些复杂的消息”只是解释测试失败的消息。它不涉及断言。在 nodeunit 中执行此操作的最佳方法是什么?

0 投票
1 回答
2255 浏览

javascript - Webstorm UT - 找不到模块

我正在尝试测试简单的代码:

在 examplesTestUnit.js 文件中:

当我尝试在 Webstorm 中运行测试时出现错误:

我安装了 mocha 进行测试,mocha 没有给我一个错误,但仍然没有结果:

我已经安装了 0.8.6 版本的 nodeunit,我已经尝试重新安装它。加上我在终端收到的另一个错误:

我正在使用 Fedora 22。我该如何解决这个问题?

0 投票
1 回答
25 浏览

javascript - 使用 nodeunit 测试 JavaScript 库 - FileApi, substr undefined

我想用 nodeunit 测试我的库,并在其中使用FileObject,在网站上一切正常(FileAPI 在那里实现)但是当我尝试用 nodeunit 测试它时出现错误:

Fatal error: File is not defined

我假设我必须添加:

在代码的乞求时,但是当我将该库包含到网站时我不需要它,如何处理?要使用 nodeunit 我必须在最后添加 module.exports ,是否也有必要?(github上的代码示例)

更重要的是,当我尝试测试此代码时: https ://github.com/GeoSmartCity-CIP/gsc-client/blob/feature/upload-data-file/src/upload/upload.js

通过这个测试:

我收到Fatal error: Cannot read property 'substr' of undefined错误,有什么问题?编辑: substr 的问题可能来自 isShapefileCorrect 函数,但仍然不知道为什么?

0 投票
1 回答
134 浏览

javascript - Nodeunit 不会运行 nodeunit 命令只是给出错误

嗨,我尝试安装 Nodeunit,但是当我尝试运行 nodeunit 命令时,它只会给出错误。下面的截图是错误的。任何帮助将不胜感激。

运行窗口 10 并使用命令“npm install nodeunit -g”安装

在此处输入图像描述

0 投票
1 回答
158 浏览

node.js - 如何使用有关 Jenkins 的报告运行 nodeunit 测试

我试图找到一种在 Jenkins 上运行 nodeunit 测试并播下结果的方法。到目前为止,我只发现了如何使用 mocha 和其他框架而不是 nodeunit。有插件或詹金斯或我应该做的事情吗?

谢谢

0 投票
0 回答
34 浏览

json - NodeUnit - 使用通配符

我正在使用 NodeUnit 对 JSON REST API 进行自动化验收测试。我有一个创建资源的测试,它返回创建的资源(根据规范),我想将 API 的结果与我自己的 JSON 对象进行比较,例如:

只有一个问题:由于测试(NodeUnit)是异步的,所以创建资源的 Id 可以是任何东西。在这种情况下是“1”,但它可能是“2”甚至是“95”。那么,是否有可能使用通配符而不是数值?

0 投票
1 回答
245 浏览

javascript - 使用外部模块进行 JavaScript 单元测试

我正在开发一个现有的节点项目,其中大多数 js 文件的代码结构如下所示。

如何在不依赖导入模块的情况下对 func1 进行单元测试?我如何模拟/存根它们?我来自 Java 世界,所以我熟悉模拟概念,但在这里我不确定如何使用 require 模拟全局声明的模块导入。

目前我们正在使用 nodeunit 进行单元测试,但它只测试很小一部分代码。

我正在阅读有关 simon.js 和 testdouble 的信息,但不确定如何使用它们来模拟全局变量。

任何帮助/方向表示赞赏。

0 投票
1 回答
126 浏览

node.js - sinon mocking GET, POST, PUT and DELETE methods assertions fail everytime. no idea why

am learning sinon and nodeUnit for nodejs. wrote simple module that handles GET, POST, PUT and DELETE methods.

then started writing unit test. Now there are two sides for my problem:

One being: in GET test when i specify requestMock.method = 'GET'; then run nodeunit test-http-module.js test fails, when reviewing call stack it says POST request failed (handlePostRequest as highlighted in call stack below).

Two being: when changing requestMock.method = 'GET'; to 'POST', 'PUT' or 'DELETE' test still fails no matter what i change! but in latter cases the call stack shows the correct method being directed to.

I think there is a single problem causing the continuous failures and that GET being directed to POST.

please explain what is wrong.

ExpectationError: Unexpected call: writeHead(200, { Content-Type: "text/plain" })

Expectation met: writeHead(200, { Content-Type: "text/plain" }[, ...]) once

at Object.fail (D:\Projects\node-book\node_modules\sinon\lib\sinon\mock-expectation.js:281:25)

at Object.invokeMethod (D:\Projects\node-book\node_modules\sinon\lib\sinon\mock.js:174:25)

at Object.writeHead (D:\Projects\node-book\node_modules\sinon\lib\sinon\mock.js:67:35)

at handlePostRequest (D:\Projects\node-book\modules\http-module.js:8:14)

at Object.handleRequest (D:\Projects\node-book\modules\http-module.js:34:26)

at Object.exports.handleGetRequestTest (D:\Projects\node-book\unit-testing-intro\test-http-module.js:22:21)