spy4js
Advanced tools
Comparing version 1.0.2 to 1.0.3
{ | ||
"name": "spy4js", | ||
"version": "1.0.2", | ||
"version": "1.0.3", | ||
"description": "Use new Spy() to optimize your tests with helpful debug messages.", | ||
@@ -44,6 +44,7 @@ "main": "dist/spy.js", | ||
"chalk": "1.1.3", | ||
"eslint": "2.8.0", | ||
"eslint-config-google": "0.4.0", | ||
"eslint": "3.13.1", | ||
"eslint-config-google": "0.7.1", | ||
"eslint-plugin-flow-vars": "0.4.0", | ||
"expect": "1.16.0", | ||
"flow-bin": "0.33.0", | ||
"flow-bin": "0.37.4", | ||
"gulp": "3.9.1", | ||
@@ -64,4 +65,5 @@ "gulp-babel": "6.1.2", | ||
"run-sequence": "1.1.5", | ||
"watchify": "3.7.0" | ||
"watchify": "3.7.0", | ||
"webpack": "1.13.0" | ||
} | ||
} |
@@ -19,8 +19,10 @@ | ||
**spy4js** provides a stand-alone spy framework. It is decoupled by any dependecies and other assertion frameworks. Other than most test frameworks it uses a different - maybe you will need to get used to - test notation. It does not make assertion, which are expected to be fulfilled on runtime, but displays facts, that are considered to be fulfilled on runtime. And if this fact is not true, it will throw an exception. I consider the way of writing facts more regular because it fits more to the rest of the written code. | ||
**spy4js** provides a stand-alone spy framework. It is decoupled by any dependencies and other assertion frameworks. Other than most test frameworks it uses a different - maybe you will need to get used to - test notation. It does not make assertion, which are expected to be fulfilled on runtime, but displays facts, that are considered to be fulfilled on runtime. And if this fact is not true, it will throw an exception. I consider the way of writing facts more regular because it fits more to the rest of the written code. | ||
**spy4js** comes with the one interesting (es6 like) class `Spy`. The spy instances are treated as class instances and come with a lot of useful features. See below for more. | ||
### Installation (TODO) | ||
### Installation | ||
Like every other npm package. You may `npm install spy4js --save-dev` to save the latest version to your dev dependencies. | ||
### Interface | ||
@@ -40,3 +42,3 @@ | ||
// initialize by mocking another objects attribute (usually this attribute is a function) | ||
const someObject = new Date(2017, 01, 15); | ||
const someObject = new Date(2017, 1, 15); | ||
const spy3 = Spy.on(someObject, 'toJSON'); | ||
@@ -46,3 +48,3 @@ // (spy name will be accordingly: 'the spy on \'toJSON\'') | ||
// initialize many by mocking another objects attributes | ||
const someObject = new Date(2017, 01, 15); | ||
const someObject = new Date(2017, 1, 15); | ||
const [spy4, spy5, spy6] = Spy.onMany(someObject, 'toJSON', 'toString', 'getDate'); | ||
@@ -72,22 +74,22 @@ ``` | ||
spy.calls(func1, func2, func3); | ||
someObject.someMethod(arg) // returns func1(arg) | ||
someObject.someMethod(arg1, arg2) // returns func2(arg1, arg2) | ||
someObject.someMethod(arg) // returns func3(arg) | ||
someObject.someMethod(arg1, arg2, arg3) // returns func3(arg1, arg2, arg3) // sticks to the last | ||
someObject.someMethod(arg); // returns func1(arg) | ||
someObject.someMethod(arg1, arg2); // returns func2(arg1, arg2) | ||
someObject.someMethod(arg); // returns func3(arg) | ||
someObject.someMethod(arg1, arg2, arg3); // returns func3(arg1, arg2, arg3) // sticks to the last | ||
// make it return any values | ||
spy.returns(value1, value2); | ||
someObject.someMethod(arg) // returns value1 | ||
someObject.someMethod(arg1, arg2) // returns value2 | ||
someObject.someMethod(arg) // returns value2 // sticks to the last | ||
someObject.someMethod(arg); // returns value1 | ||
someObject.someMethod(arg1, arg2); // returns value2 | ||
someObject.someMethod(arg); // returns value2 // sticks to the last | ||
// make it throw any message (the message is optional) | ||
spy.throws('throw this'); | ||
someObject.someMethod(arg) // throws new Error('throw this') | ||
someObject.someMethod(arg); // throws new Error('throw this') | ||
// make it return always the current date and transparentAfter 2 calls | ||
spy.calls(() => new Date()).transparentAfter(2); | ||
someObject.someMethod(arg) // returns new Date() | ||
someObject.someMethod(arg1, arg2) // returns new(er) Date() | ||
someObject.someMethod(arg) // returns someObject.someMethod(arg) // sticks to this behaviour | ||
someObject.someMethod(arg); // returns new Date() | ||
someObject.someMethod(arg1, arg2); // returns new(er) Date() | ||
someObject.someMethod(arg); // returns someObject.someMethod(arg) // sticks to this behaviour | ||
@@ -155,16 +157,16 @@ // make it immediatly transparent | ||
spy.getCallArguments(/* default = 0 */) // returns ['string', 1] | ||
spy.getFirstCallArgument(/* default = 0 */) // returns 'string' | ||
spy.getCallArguments(/* default = 0 */); // returns ['string', 1] | ||
spy.getFirstCallArgument(/* default = 0 */); // returns 'string' | ||
spy.getCallArguments(1) // returns [[1, 2, 3]] | ||
spy.getFirstCallArgument(1) // returns [1, 2, 3] | ||
spy.getCallArguments(1); // returns [[1, 2, 3]] | ||
spy.getFirstCallArgument(1); // returns [1, 2, 3] | ||
spy.getCallArguments(2) // returns [] | ||
spy.getFirstCallArgument(2) // returns undefined | ||
spy.getCallArguments(2); // returns [] | ||
spy.getFirstCallArgument(2); // returns undefined | ||
spy.getCallArguments(3) // returns [null] | ||
spy.getFirstCallArgument(3) // returns null | ||
spy.getCallArguments(3); // returns [null] | ||
spy.getFirstCallArgument(3); // returns null | ||
spy.getCallArguments(4) // throws Exception because less calls were made | ||
spy.getFirstCallArgument(4) // throws same Exception | ||
spy.getCallArguments(4); // throws Exception because less calls were made | ||
spy.getFirstCallArgument(4); // throws same Exception | ||
``` | ||
@@ -171,0 +173,0 @@ |
67356
171
33