人们使用哪些 javascript 模拟框架?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6679914/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-25 21:29:51  来源:igfitidea点击:

What javascript mocking frameworks are people using?

javascriptnode.jstddmockingbdd

提问by James Hollingworth

I'm using Jasmine for testing client & server side javascript and need to do some mocking. Has anyone got any suggestions for a good javascript mocking framework?

我正在使用 Jasmine 测试客户端和服务器端 javascript,需要做一些模拟。有没有人对一个好的 javascript 模拟框架有任何建议?

采纳答案by Joshua Dale

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/

我尝试过一次,但最终进行了重构,因此不需要它。它没有依赖关系,所以它应该可以在 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

这些是测试框架,但其中一些包含内部模拟框架:http: //en.wikipedia.org/wiki/List_of_unit_testing_frameworks#JavaScript

回答by Alfred

I have not tried this one out(yet), but you could try node-gentlycreated by Felix Geisend?rfer. Right now I saw nodemockupdate at search.npmjs.org which is commited frequently also.

我还没有尝试过这个(还),但你可以尝试由 Felix Geisend?rfer 创建的节点。现在我在 search.npmjs.org看到nodemock更新,它也经常提交

Quick search gave me:

快速搜索给了我:

回答by masylum

I'm using node-gently and it works great. Is not as complete as sinon but feels more confortable to work with.

我正在轻轻地使用节点,并且效果很好。不像 sinon 那样完整,但感觉更舒适。

回答by Raynos

Why do you need a mocking framework? In statically-typedlanguages you need one because you can't change types at run-time.

为什么需要模拟框架?在静态类型语言中,您需要一个,因为您不能在运行时更改类型。

I don't think you needthis with JavaScript, the language is dynamic and powerful enough for you to not need this.

我认为JavaScript不需要这个,该语言是动态且强大的,你不需要这个。

For example, I use backbonefor my models and for the database connectivity. Backbone was designed well and has a single method Backbone.Syncthat does all the database magic.

例如,我backbone用于我的模型和数据库连接。Backbone 设计得很好,并且有一个方法Backbone.Sync可以完成所有的数据库魔法。

So I just do

所以我只是做

var Backbone = require("backbone");
Backbone.Sync = function _mockedSync() {
  return ...;
}

You need to clarify exactly whatyou need. I don't think you needa mocking framework.

你需要明确你需要什么。我认为您不需要模拟框架。