Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What javascript mocking frameworks are people using? [closed]

Tags:

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?

like image 473
James Hollingworth Avatar asked Jul 13 '11 13:07

James Hollingworth


People also ask

Are mocks a code smell?

Mock Objects are a Code Smell But mock objects are more often smelly because they are telling you something about the system under test. A Code Smell is defined as “a hint that something has gone wrong somewhere in your code”.

What JavaScript unit testing frameworks are you most experienced with?

Jest was the most popular JavaScript unit testing framework in 2020. For web apps that are based on React, Jest is the preferred framework. Apart from React, Jest supports unit testing of Angular, VueJS, NodeJS, and others.

What is Sinon used for?

Sinon JS is a popular JavaScript library that lets you replace complicated parts of your code that are hard to test for “placeholders,” so you can keep your unit tests fast and deterministic, as they should be.


2 Answers

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

like image 87
Joshua Dale Avatar answered Sep 28 '22 10:09

Joshua Dale


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:

  • https://github.com/aikar/mock
  • https://github.com/arunoda/nodemock
  • https://github.com/dhasenan/maryjane
  • https://github.com/cjohansen/Sinon.JS
  • https://github.com/dominictarr/remap
like image 37
Alfred Avatar answered Sep 28 '22 11:09

Alfred