Tag: unit testing

运行testing时npm错误ELIFECYCLE

我正在使用mocha-phantomjs设置进行unit testing。 我有以下package.json脚本运行testing。 "scripts": { "test": "npm run testFlickr", "testFlickr": "mocha-phantomjs ./test/FlickrTest.html" } 这在浏览器中运行正常。 当我运行cmd命令npm test时,testing运行正常,但它也给出了以下错误 3 passing (5s) 6 failing npm ERR! flickr-test@ testFlickr: `mocha-phantomjs ./test/FlickrTest.html` npm ERR! Exit status 6 npm ERR! npm ERR! Failed at the flickr-test@ testFlickr script. npm ERR! This is most likely a problem with the flickr-test package, npm […]

用Jasmine / NodetestingAngular:未捕获types错误“不能设置'mock'的属性undefined

我正在尝试创build“Angular.js in Action”中描述的Jasmineunit testing。 该应用程序运行正常,但我试图运行我的testing时,不断收到此错误在node.js命令提示符。 我的configuration: module.exports = function(config) { config.set({ // base path, that will be used to resolve files and exclude basePath: '', // frameworks to use frameworks: ['jasmine'], // list of files / patterns to load in the browser files: [ 'javascripts/angular.min.js', 'javascripts/angular-mocks.js', 'javascripts/app.js', 'tests/angelloModelSpec.js', ], 我的index.html标题: <head> <script src="javascripts/angular.min.js" type="text/javascript"></script> <script […]

为什么茉莉花节点不拿起我的帮手脚本?

这个问题很可能是因为我缺乏以前使用node.js的经验,但是我希望jasmine-node只是让我从命令行运行我的jasmine规范。 TestHelper.js: var helper_func = function() { console.log("IN HELPER FUNC"); }; my_test.spec.js: describe ('Example Test', function() { it ('should use the helper function', function() { helper_func(); expect(true).toBe(true); }); }); 这些是目录中唯一的两个文件。 那么,当我这样做: jasmine-node . 我明白了 ReferenceError: helper_func is not defined 我敢肯定这个答案很简单,但是我没有find任何超级简单的介绍,或者在github上的任何明显的例子。 任何意见或帮助将不胜感激! 谢谢!

Nodeunit test.throws似乎没有发现错误

我正在尝试为使用Nodeunit在Node.js中编写的模块创build一个testing套件。 该模块是一个基本的音乐播放列表,允许添加和删除曲目的播放列表。 var playlist = function(){ this.__playlist = []; this.__count = 0; }; playlist.prototype = { addtrack:function(track){ if(typeof track !== "object") throw new Error("Track needs to be an oject"); this.__count++; track.id = this.__count; this.__playlist.push(track); return this.__playlist; }, removetrack:function(trackid){ if(typeof trackid !== "number") throw new Error("Pass in a numeric track id"); var trackFound = false; for(var […]

在Webstorm 11中用jasmine运行/debuggingnode.jstesting用例

我安装Webstorm 11,并想运行我的testing(对于node.js应用程序)与茉莉花实施。 然而这并不容易。 我只能input命令行'jasmine'命令,testing将运行,但在这种情况下,我无法debugging代码。 那么有没有办法configurationWebstorm处理茉莉花规格?

使用(substack's)磁带模块进行testing时,如何在文件中只运行一个testing?

使用磁带时如何运行特定的testing并忽略所有其他testing?

在摩卡testing预期的失败

使用摩卡,我试图testing一个构造函数是否抛出一个错误。 我还没有能够使用期望的语法做到这一点,所以我想要做到以下几点: it('should throw exception when instantiated', function() { try { new ErrorThrowingObject(); // Force the test to fail since error wasn't thrown } catch (error) { // Constructor threw Error, so test succeeded. } } 这可能吗?

PhantomJS退出意外退出代码-1073741819

我在Windows 7 PC上用PhantomJS(通过Grunt)运行一些Jasmine规格,而且碰巧遇到以下错误: Testing jasmine specs via phantom …… Running PhantomJS…ERROR >> 0 [ '' ] Warning: PhantomJS exited unexpectedly with exit code -1073741819. Use –force to continue. Aborted due to warnings. 如果我删除一堆testing,错误不会出现; 但是我不知道是什么原因导致错误。 我也觉得奇怪,它只是偶尔发生。 任何想法为什么发生这种情况

unit testing使用服务方法的节点js控制器的最佳方法是什么?

我的控制器=>下面的控制器是使用reqpoertService.getFiles方法,该方法本身使用外部的API来调用数据。 function getFiles(req, res) { reportService.getFiles({ fromDate: req.query.fromdate, endDate: req.query.enddate, fileTypes: req.query.filetypes || [], fileStatus: req.query.filestatus || [] }) .then(data => { logger.info('-> reportService.getFiles :: Successfully fetched data', resolveLogger({ statusCode: res.statusCode }) ); res.send(data); }) .catch(err => { logger.error('<- OOPS :: reportService.getFiles fail to fetch data'); res.status(statusCodes.INTERNAL_SERVER_ERROR).send({}); logger.error('<- ERROR', resolveLogger({ statusCode: res.statusCode, errMessage: err.message, errorStack: […]

如何为express.static模拟http.ServerResponse和http.IncomingMessage

我没有麻烦testing自己的路由处理程序,但在这种情况下,我想testing快递的静态处理程序。 我不能为了我的生活找出它为什么挂。 显然有一些callback我失踪或一些事件,我需要发出。 我尽力做出最小的例子。 var events = require('events'); var express = require('express'); var stream = require('stream'); var util = require('util'); function MockResponse(callback) { stream.Writable.call(this); this.headers = {}; this.statusCode = -1; this.body = undefined; this.setHeader = function(key, value) { this.headers[key] = value; }.bind(this); this.on('finish', function() { console.log("finished response"); callback(); }); }; util.inherits(MockResponse, stream.Writable); MockResponse.prototype._write = function(chunk, […]