Socket
Socket
Sign inDemoInstall

spy4js

Package Overview
Dependencies
Maintainers
1
Versions
75
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

spy4js - npm Package Compare versions

Comparing version 1.0.7 to 1.1.0

55

dist/spy.js

@@ -40,2 +40,12 @@ 'use strict';

/**
* Initial default settings for every
* spy instance. Can be modified only
* implicitly by "Spy.configure".
*
* @type {{useOwnEquals: boolean}}
*/
var DefaultSettings = {
useOwnEquals: true };
/**
* @ModifiedOnly by viktor.luft@freiheit.com

@@ -91,3 +101,3 @@ *

spy[Symbols.calls] = [];
spy[Symbols.config] = { useOwnEquals: true };
spy[Symbols.config] = { useOwnEquals: DefaultSettings.useOwnEquals };
for (var key in Spy.prototype) {

@@ -102,3 +112,22 @@ if (Spy.prototype instanceof Object && Spy.prototype.hasOwnProperty(key)) {

/**
* This static method can be used to configure
* the default behaviour of created spy instances.
*
* For example,
*
* Spy.configure({useOwnEquals: false});
*
* would initially configure every spy to not
* favor own "equals" implementation while
* comparing any objects.
*
* @param {Object} config <- Holds the configuration params.
*/
Spy.configure = function configure(config) {
if (config.useOwnEquals !== undefined) {
DefaultSettings.useOwnEquals = config.useOwnEquals;
}
};
/**
* This static method is an alternative way to

@@ -532,3 +561,3 @@ * create a Spy which mocks the an objects attribute.

/**
* This method returns the first call argument of the
* This method returns the m'th call argument of the
* n'th made call. If less than n calls were made, it will throw

@@ -538,2 +567,3 @@ * an error.

* By default n = 1. This corresponds to callNr = 0.
* By default m = 1. This corresponds to argNr = 0.
*

@@ -543,13 +573,24 @@ * For example:

* spy(arg1, arg2, arg3);
* spy.getFirstCallArgument() === arg1; // true
* spy(arg4, arg5, arg6);
* spy.getCallArgument() === arg1; // true
* spy.getCallArgument(1) === arg4; // true
* spy.getCallArgument(0, 2) === arg3; // true
* spy.getCallArgument(1, 1) === arg5; // true
*
* spy.getCallArgument(1, 5) === undefined; // true
* spy.getCallArgument(2); // throws an exception
*
* @param {number} callNr -> represents the callNr for which
* the first call argument should be returned.
* a call argument should be returned.
* @param {number} argNr -> represents position of the argument
* when the corresponding call was made.
*
* @return {any} -> the first call argument of the (callNr + 1)'th call.
* @return {any} -> the (argNr + 1)'th call argument
* of the (callNr + 1)'th call.
*/
Spy.prototype.getFirstCallArgument = function () {
Spy.prototype.getCallArgument = function () {
var callNr = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
var argNr = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
return this.getCallArguments(callNr)[0];
return this.getCallArguments(callNr)[argNr];
};

@@ -556,0 +597,0 @@

2

package.json
{
"name": "spy4js",
"version": "1.0.7",
"version": "1.1.0",
"description": "Use new Spy() to optimize your tests with helpful debug messages.",

@@ -5,0 +5,0 @@ "main": "dist/spy.js",

@@ -58,5 +58,11 @@

Any spy instance can be configured by overriding the default configuration. For
example if you want to configure all spies not to favor own "equals" implementations.
```js
Spy.configure({useOwnEquals: false});
```
You may apply additional behaviour to every spy. The valid operations here are:
- `configure` (some external librarys may use own "equals" implementations in an unexpected way)
- `configure` (some external libraries may use own "equals" implementations in an unexpected way)
- `calls` (does make the spy call the provided functions sequentially)

@@ -159,3 +165,3 @@ - `returns` (does make the spy return the provided params sequentially)

- `getCallArguments` (returns all call arguments for a specified call in an array)
- `getFirstCallArgument` (same as getCallArguments, but returns only the first element of the array)
- `getCallArgument` (same as getCallArguments, but returns only a single element of the array)
- `getCallCount` (returns the number of made calls)

@@ -173,15 +179,16 @@

spy.getCallArguments(/* default = 0 */); // returns ['string', 1]
spy.getFirstCallArgument(/* default = 0 */); // returns 'string'
spy.getCallArgument(/* defaults = (0, 0) */); // returns 'string'
spy.getCallArgument(0, 1); // returns 1
spy.getCallArguments(1); // returns [[1, 2, 3]]
spy.getFirstCallArgument(1); // returns [1, 2, 3]
spy.getCallArgument(1); // returns [1, 2, 3]
spy.getCallArguments(2); // returns []
spy.getFirstCallArgument(2); // returns undefined
spy.getCallArgument(2); // returns undefined
spy.getCallArguments(3); // returns [null]
spy.getFirstCallArgument(3); // returns null
spy.getCallArgument(3); // returns null
spy.getCallArguments(4); // throws Exception because less calls were made
spy.getFirstCallArgument(4); // throws same Exception
spy.getCallArgument(4); // throws same Exception
```

@@ -200,2 +207,10 @@

### configure (static)
```
Spy.configure(config:{useOwnEquals?:boolean}) => void
```
Using this function you may edit the default behaviour of every spy instance. The only
configuration possibility for now is "useOwnEquals". See [configure](#configure) for more
details.
### on (static)

@@ -338,9 +353,11 @@ ```

Throws an exception if the provided (`callNr` - 1) is bigger than the made calls.
### getFirstCallArgument
### getCallArgument
```
spy.getFirstCallArgument(callNr:number = 0) => any
spy.getCallArgument(callNr:number = 0, argNr:number = 0) => any
```
Same as [getCallArguments](#getcallarguments) but returns the only the first entry out
Same as [getCallArguments](#getcallarguments) but returns only a single entry out
of the array of arguments. Most useful in situations where exactly one call param is expected.
If `argNr` is given, it returns the (argNr + 1)'th argument of the call.

@@ -412,2 +429,6 @@ ### getCallCount

* **1.1.0:**
* Implemented `getCallArgument` as extension of `getFirstCallArgument`.
* Removed `getFirstCallArgument`.
* Added global configuration possibility on Spy.
* **1.0.7:**

@@ -414,0 +435,0 @@ * Removed expect-dev-dependency.

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc