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.3.3 to 1.4.0

8

dist/registry.js

@@ -32,4 +32,10 @@ 'use strict';

*/
/**
* This file is part of spy4js which is released under MIT license.
*
* The LICENSE file can be found in the root directory of this project.
*
*
*/
function SpyRegistry() {

@@ -36,0 +42,0 @@ if (!(this instanceof SpyRegistry)) {

@@ -66,3 +66,9 @@ 'use strict';

return displayedType + '{' + results.join(', ') + '}';
};
}; /**
* This file is part of spy4js which is released under MIT license.
*
* The LICENSE file can be found in the root directory of this project.
*
*
*/

@@ -69,0 +75,0 @@ var serialize = exports.serialize = function serialize(o) {

@@ -27,3 +27,9 @@ 'use strict';

*/
var registry = new _registry.SpyRegistry();
var registry = new _registry.SpyRegistry(); /**
* This file is part of spy4js which is released under MIT license.
*
* The LICENSE file can be found in the root directory of this project.
*
*
*/

@@ -437,3 +443,3 @@ var __LOCK__ = true;

*
* If callCount = 0 - which is the default - then it only
* If callCount is not provided then it only
* checks if the spy was called at least once.

@@ -445,7 +451,5 @@ *

*/
Spy.prototype.wasCalled = function () {
var callCount = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
Spy.prototype.wasCalled = function (callCount) {
var madeCalls = this[Symbols.calls].length;
if (callCount) {
if (typeof callCount === 'number') {
if (madeCalls !== callCount) {

@@ -460,2 +464,28 @@ throw new Error('\n\n' + this[Symbols.name] + ' was called ' + madeCalls + ' times,' + (' but there were expected ' + callCount + ' calls.\n\n'));

/**
* Checks if the spy was call history matches the expectation.
*
* The call history has to match the call count and order.
*
* Throws an error if the expectation is wrong.
*
* @param {Array<Array<any>>} callHistory
* -> Are the expected made call arguments in correct order.
*/
Spy.prototype.hasCallHistory = function (callHistory) {
var madeCalls = this[Symbols.calls];
var callCount = callHistory.length;
if (madeCalls.length !== callCount) {
throw new Error('\n\n' + this[Symbols.name] + ' was called ' + madeCalls.length + ' times,' + (' but the expected call history includes exactly ' + callHistory.length + ' calls.\n\n'));
}
var hasErrors = false;
var diffInfo = [];
for (var i = 0; i < madeCalls.length; i++) {
var diff = (0, _utils.differenceOf)(madeCalls[i].arguments, callHistory[i], this[Symbols.config]);
diffInfo.push(diff || '');
if (diff) hasErrors = true;
}
if (hasErrors) throw new Error('\n\n' + this[Symbols.name] + ' was considered' + ' to be called with the following arguments in the given order:\n\n' + (' --> ' + (0, _serializer.serialize)(callHistory) + '\n\n') + 'Actually there were:\n\n' + this.showCallArguments(diffInfo));
};
/**
* Checks that the spy was never called.

@@ -462,0 +492,0 @@ * Throws an error if the spy was called at least once.

@@ -19,2 +19,10 @@ 'use strict';

/**
* This file is part of spy4js which is released under MIT license.
*
* The LICENSE file can be found in the root directory of this project.
*
*
*/
/**
* This function takes a handler as second argument to process

@@ -21,0 +29,0 @@ * all key-value-pairs of the given object through this handler.

8

package.json
{
"name": "spy4js",
"version": "1.3.3",
"version": "1.4.0",
"description": "Smart, compact and powerful spy test framework",

@@ -26,3 +26,3 @@ "jest": {

"scripts": {
"build": "rm -r dist && babel src --out-dir dist && for i in `ls src/`; do cp src/$i dist/$i.flow; done",
"build": "rm -rf dist && babel src --out-dir dist && for i in `ls src/`; do cp src/$i dist/$i.flow; done",
"eslint": "eslint src/ test/",

@@ -47,3 +47,3 @@ "flow": "flow --quiet",

],
"author": "Viktor Luft",
"author": "Viktor Luft <viktor.luft@freiheit.com> (https://github.com/fdc-viktor-luft)",
"license": "MIT",

@@ -67,3 +67,3 @@ "dependencies": {},

"eslint-plugin-prettier": "^2.3.1",
"flow-bin": "^0.57.3",
"flow-bin": "^0.66.0",
"jest": "^21.2.1",

@@ -70,0 +70,0 @@ "prettier": "1.7.4"

@@ -0,6 +1,8 @@

[![GitHub license][license-image]][license-url]
[![npm package][npm-image]][npm-url]
[![Travis][build-image]][build-url]
[![Coverage Status][coveralls-image]][coveralls-url]
[![styled with prettier][prettier-image]][prettier-url]
# spy4js
# ![spy4js logo](spy-logo.svg) spy4js

@@ -123,2 +125,3 @@ ### Benefits

- `wasNotCalledWith` (does display that the spy was never like with the provided params)
- `hasCallHistory` (does display that the spy was called with the following params in the given order)

@@ -146,5 +149,10 @@ Those methods on a spy display facts. Facts have to be true, otherwise they

spy.wasCalledWith([1, 'test', {attr: [4]}]); // the spy was called at least once with equal params
// the spy was called at least once with equal params
spy.wasCalledWith([1, 'test', {attr: [4]}]);
spy.wasNotCalledWith([1, 'test', {attr: [3]}]); // the spy was not called with those params
// the spy was not called with those params
spy.wasNotCalledWith([1, 'test', {attr: [3]}]);
// the spy was called twice with the following params and in same order
spy.hasCallHistory([ [ [1, 'test', {attr: [4]}] ], [ 'with this text' ] ]);
```

@@ -382,2 +390,9 @@

### hasCallHistory
```
spy.hasCallHistory(callHistory:Array<Array<any>>) => (fact) void
```
Works similiar to [wasCalledWith](#wascalledwith) but instead matches each
call one by one in **correct order** and **correct call count**.
### getCallArguments

@@ -467,2 +482,4 @@ ```

[license-image]: https://img.shields.io/badge/license-MIT-blue.svg
[license-url]: https://github.com/fdc-viktor-luft/form4react/blob/master/LICENSE
[build-image]: https://img.shields.io/travis/fdc-viktor-luft/spy4js/master.svg?style=flat-square

@@ -473,2 +490,4 @@ [build-url]: https://travis-ci.org/fdc-viktor-luft/spy4js

[coveralls-image]: https://coveralls.io/repos/github/fdc-viktor-luft/spy4js/badge.svg?branch=master
[coveralls-url]: https://coveralls.io/github/fdc-viktor-luft/spy4js?branch=master
[coveralls-url]: https://coveralls.io/github/fdc-viktor-luft/spy4js?branch=master
[prettier-image]: https://img.shields.io/badge/styled_with-prettier-ff69b4.svg
[prettier-url]: https://github.com/prettier/prettier

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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