Tag: unit testing

require.main.require工作,但不在摩卡testing

我写了一个全局函数来要求我的应用程序/框架的某些文件: global.coRequireModel = function(name) { // CRASH happens here return require.main.require('./api/_co' + name + '/_co' + name + '.model'); } 这个模块在/ components / coGlobalFunctions中。 这是我的主要应用程序app.js需要这样的: require('./components/coGlobalFunctions'); 然后在其他模块中使用框架中的“东西”,我使用: var baseScheme = coRequireModel('Base'); 这工作,但不是在摩卡testing,给我一个“错误:无法find模块”在require.main.require调用之前。 看来testing来自另一个源文件夹。 但是我认为require.main.require会把相对连接模块的方面拿掉。 编辑: 生活在api / user中的示例testing文件: var should = require('should'); var app = require('../../app'); var User = require('./user.model'); …

Jest:找不到模块内部需要testing的模块(相对path)

我有这个组件: import React from 'react'; import VideoTag from './VideoTag'; import JWPlayer from './JWPlayer'; class VideoWrapper extends React.Component { //… component code } 基于一些逻辑呈现另一个组件(VideoTag或JWPlayer),但当我试图在一个笑话文件中testing它,我得到的错误: 找不到模块'./VideoTag' 这三个组件都在同一个目录下,这就是为什么当我在浏览器中运行它并在运行时看到它实际工作的原因,但看起来Jest在解决这些相对path时遇到了问题,这是一个笑话文件: jest.dontMock('../src/shared/components/Video/VideoWrapper.jsx'); import React from 'react'; import ReactDOM from 'react-dom'; TestUtils from 'react-addons-test-utils'; import VideoWrapper from '../src/shared/components/Video/VideoWrapper.jsx'; describe('VideoWrapper tests', () => { it('Render JWPlayer', () => { let vWrapper = TestUtils.renderIntoDocument( […]

使用cloud9的摩卡testing,从node.js执行摩卡testing

我想知道是否有办法从node.js以编程方式执行mochatesting,以便我可以将unit testing与Cloud 9集成在一起。云9 IDE具有很好的function,只要保存javascript文件,它就会查找带有相同的名称,以“_test”或“Test”结尾,并使用node.js自动运行。 例如,它有一个自动运行的文件demo_test.js中的代码片段。 if (typeof module !== "undefined" && module === require.main) { require("asyncjs").test.testcase(module.exports).exec() } 有没有这样的事情,我可以用来运行摩卡testing? 像摩卡(this).run()?

JSunit testing:对文件更改运行testing(如nodemon)

JSunit testing有两个问题: 1)是否有一些工具,允许在某些文件更改时自动运行javascriptunit testing(例如nodemon重新启动js上的node.js更改)。 2)这个策略是否合适(有效)的方式来运行unit testing? 谢谢,Alex

找不到模块:错误:无法parsing模块'react-addons-test-utils'

我有一个ES6项目,我使用webpack将客户端代码转换为ES5。 该项目在客户端使用ReactJS,所以unit testing自然使用React TestUtils。 在最新的更新(0.14)中,React 改变了几个模块的导入方式 (包括TestUtils)。 我想更新,但我不知道如何使更改导入后unit testing工作。 当我尝试运行testing时,我收到以下消息: 04 12 2015 12:40:48.038:ERROR [karma]: { [Error: no such file or directory] code: 'ENOENT', errno: 34, message: 'no such file or directory', path: '/_karma_webpack_/public/test/main.js' } Error: no such file or directory at MemoryFileSystem.readFileSync (<project>/node_modules/karma-webpack/node_modules/webpack-dev-middleware/node_modules/memory-fs/lib/MemoryFileSystem.js:107:10) at MemoryFileSystem.readFile (<project>/node_modules/karma-webpack/node_modules/webpack-dev-middleware/node_modules/memory-fs/lib/MemoryFileSystem.js:297:21) at doRead (<project>/node_modules/karma-webpack/index.js:156:26) at Plugin.readFile (<project>/node_modules/karma-webpack/index.js:160:3) at doNTCallback0 […]

量angular器E2E – 你如何pipe理数据库?

我目前正在学习Node + Angular堆栈,并使用Karma和Protractor进行testing。 我目前很难弄清楚如何处理创build和编辑数据的E2Etesting,以及是否需要加载预期的数据。 search谷歌变成了很多不同的自定义方法。 我经常读到“你应该build立你的数据”或“只是创build一个模拟”,而不用在一个普通的过程中进行更多的细节。 其他人从头开始创build一个全新的模拟模块,花费太多。 我只想知道人们目前是怎么做的,这是否有一个标准呢? 还是人们倾向于嘲笑后端? 嘲笑后端似乎不像Karma,因为你在浏览器范围内简单。 我正如预期的那样使用MongoDB,所以在这种情况下如何获得其他方面的信息是很好的。 特别是通过量angular器来自动装载夹具和清理数据库会很好。

使用时,testing不显示通过

我第一次testing我写一个testing用例 var should = require("should") describe('Array', function(){ describe('#indexOf()', function(){ it('should return -1 when the value is not present',function(){ [1,2,3].indexOf(5).should.equal(-1); [1,2,3].indexOf(0).should.equal(-1); }) }) }) 它给我0通过 0 passing (1ms) 但为什么它应该显示1通过

我应该如何使用摩卡和mongoose?

运行testing时,我一直在save()方法中发生错误。 var User = require('../../models/user') , should = require('should'); describe('User', function(){ describe('#save()', function(){ it('should save without error', function(done){ var user = new User({ username : 'User1' , email : 'user1@example.com' , password : 'foo' }); user.save(function(err, user){ if (err) throw err; it('should have a username', function(done){ user.should.have.property('username', 'User1'); done(); }); }); }) }) }) 这里是错误的: […]

Assert.fail(node.js):运算符参数是什么意思?

Node.jsunit testing模块有基本的assertion assert.fail: assert.fail(actual, expected, message, operator) operator是什么意思? 我真的很陌生,unit testing…

如何testing一个Grunt任务? 理解和最佳实践

理解如何编写复杂的Gruntfile.js并在testing中使用它,我有点Gruntfile.js 。 我是否正确使用Grunt? 我想问社区的帮助,并以另一种方式作出贡献。 我正在为Grunt写一个新的任务 ,并希望在Github和npm上为广泛的读者推出它。 我想为这个任务进行自动化testing(我想学习如何正确执行)。 我想testing不同的选项组合(现在大约15个)。 所以,我应该多次: 运行清理 运行我的任务设置下一个选项 运行testing并将选项对象传递给testing 一些非工作代码,以便更好地理解: Gruntfile: grunt.initConfig({ test_my_task: { testBasic: { options: { //first set } }, testIgnore: { options: { //another set } }, //… } clean: { tests: ['tmp'] // mmm… clean test directory }, // mmm… unit tests. nodeunit: { tests: ['test/*.js'] //tests code […]