Last Updated: March 23, 2016
·
345
· peter_heard01

5 Javascript Test Doubles You Should Know About

Knowing 5 basic Test Doubles should be about all you need to get unit testing right in any large scale enterprise application.

Test Doubles have 3 main purposes.

To stop IO from happening — this would makes tests slow an unreliable since they should be able to run anywhere
To track the internal state — this means we can check certain things happened or were left in a certain state once execution has finished
To force the system into a desired state — sometimes we want to pretend we the system is already in some predetermined state

I’ve written a blog with information on 5 Test Doubles as follows….

Dummy Objects — Are simply objects that allow our code to run/compile.
Stub Objects — Are types of Dummy object preconfigured values which we can use to force our system into a desired state.
Spy Objects — Are types of Dummy object that allow us to track when something was called on them.
Mock Objects — Are types of double object which expose our properties in such a way that show a ‘behavioural surface area’.
Fake Objects — Are types of object that contain ‘fake’ business logic. They can be used in places where complexity needs to be mimicked.

You can see the blog here..

http://www.peteheard.com/javascript/javascript-test-doubles/