What javascript mocking frameworks are people using? [closed]

不羁岁月 提交于 2019-12-03 02:20:08

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

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:

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

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!