I tried this once, but ended up refactoring instead so it wasn't needed. It doesn't have dependencies, so it should work just fine on node.js. http://sinonjs.org/
I have not tried this one out(yet), but you could try node-gently created by Felix Geisendörfer. Right now I saw nodemock update at search.npmjs.org which is commited frequently also.
var Backbone = require("backbone");
Backbone.Sync = function _mockedSync() {
return ...;
}
你需要澄清你到底需要什么。我认为您不需要一个模拟框架。
Why do you need a mocking framework? In statically-typed languages you need one because you can't change types at run-time.
I don't think you need this with JavaScript, the language is dynamic and powerful enough for you to not need this.
For example, I use backbone for my models and for the database connectivity. Backbone was designed well and has a single method Backbone.Sync that does all the database magic.
So I just do
var Backbone = require("backbone");
Backbone.Sync = function _mockedSync() {
return ...;
}
You need to clarify exactly what you need. I don't think you need a mocking framework.
发布评论
评论(4)
我尝试过一次,但最终进行了重构,所以不需要它。它没有依赖项,因此它应该可以在 Node.js 上正常工作。 http://sinonjs.org/
这些是测试框架,但其中一些内部包含模拟框架:http://en.wikipedia.org/wiki/List_of_unit_testing_frameworks#JavaScript
I tried this once, but ended up refactoring instead so it wasn't needed. It doesn't have dependencies, so it should work just fine on node.js. http://sinonjs.org/
These are testing frameworks, but some of them include mocking frameworks internally: http://en.wikipedia.org/wiki/List_of_unit_testing_frameworks#JavaScript
我还没有尝试过这个,但是你可以尝试由创建的 node-gently
菲利克斯·盖森多夫。现在我在 search.npmjs.org 上看到 nodemock 更新,该更新也经常提交。
快速搜索给了我:
I have not tried this one out(yet), but you could try node-gently created by
Felix Geisendörfer. Right now I saw nodemock update at search.npmjs.org which is commited frequently also.
Quick search gave me:
我正在使用node-gently,效果很好。不像 sinon 那样完整,但使用起来感觉更舒服。
I'm using node-gently and it works great. Is not as complete as sinon but feels more confortable to work with.
为什么需要一个模拟框架?在静态类型语言中,您需要一个静态类型,因为您无法在运行时更改类型。
我认为您在 JavaScript 中需要这个,该语言是动态的并且足够强大,您不需要它。
例如,我将
backbone
用于我的模型和数据库连接。 Backbone 设计得很好,并且有一个方法Backbone.Sync
可以完成所有数据库魔法。所以我只是做
你需要澄清你到底需要什么。我认为您不需要一个模拟框架。
Why do you need a mocking framework? In statically-typed languages you need one because you can't change types at run-time.
I don't think you need this with JavaScript, the language is dynamic and powerful enough for you to not need this.
For example, I use
backbone
for my models and for the database connectivity. Backbone was designed well and has a single methodBackbone.Sync
that does all the database magic.So I just do
You need to clarify exactly what you need. I don't think you need a mocking framework.