soother
soother is a cross-browser standalone library that provide test dummies, stubs, mocks, fakes and spies for JavaScript. Works with any unit testing framework.
Notes
It's a quite different but very simple.
The library makes use of an idiomatically different style than other libraries that using stubs.
Feel free to open merge requests with upgrades and report issues.
Getting Started
npm install soother --save-dev
Dummy
A minimal function is which does nothing and returns nothing
from 'K&R' (c)
; const instance = ; instancetest = Soother; instance; const firstCall = instancetestcalls; const argOfCall = firstCallargs; to;
Stub
const stubbedInstance = Soother; stubbedInstance; stubbedInstance; stubbedInstance; stubbedInstance; stubbedInstance; stubbedInstance; to; to; to; const methodCall = stubbedInstancetestcalls; const callArg = methodCallargs; to;
Mock
let mockInstance = Soother; mockInstancetestProperty = 1; to; to; mockInstance = Soother; to; mockInstance; to;
Spy
const spyInstance = Soother; spyInstance; const prop = spyInstancetestProperty; to; spyInstancetestProperty = 'spy'; spyInstancetest = 'spy'; const sets gets = spyInstancespied; const firstSet = sets; const firstGet = gets; to; to; to; to; to;
Fake AJAX
Example with XMLHttpRequest
; const url = 'http://www.test.org/test.txt'; const fake = Soother; fake; const oReq = ; oReq { to; }; oReq; oReq; oReq; to; to; const firstCall = fake; to; to; to; const methods = fake; to;
Example with axios
; ; /** * Call specific endpoint via HTTP and read items * * @returns */ { return Axios; }
; ;
You also can setup fake backend with end-point mocks
; // TODO remove after integration { const fakeAjax = Soother; const url = '/api/v1/item'; const list = name: '9' name: '10' ; const item = name: '11' ; fakeAjax; fakeAjax; fakeAjax; fakeAjax;}
Stub and Mock CommonJS modules
const ms = Soother; ms; ms; const svg1 = ; const svg2 = ; const css1 = ; const css2 = ; to; to; to; to;
Alternatives
Tests
cd soother
npm i
npm test
Then check ./coverage/report.html
License
Copyright (c) 2017 artur.basak aka archik Licensed under the Apache-2.0 license.