New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

jestor

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jestor - npm Package Compare versions

Comparing version 1.0.6 to 1.0.7

12

dist/jestor.js

@@ -10,3 +10,3 @@ 'use strict';

ruleGetter({
whenCalledWith: getRuleBuilder((rule) => rules.push(rule)),
whenCalledWith: getRuleBuilder((rule) => rules.push(rule))
});

@@ -31,3 +31,3 @@ return jestMock.mockImplementation((...actualArgs) => {

});
}),
})
};

@@ -44,5 +44,5 @@ }

pass: true,
message: () => '',
message: () => ''
};
},
}
});

@@ -73,3 +73,3 @@ expect(1)[MATCHER_NAME]();

valueWrapper: undefined,
returnValue: undefined,
returnValue: undefined
};

@@ -98,3 +98,3 @@ return {

collectRule(rule);
},
}
};

@@ -101,0 +101,0 @@ };

{
"name": "jestor",
"version": "1.0.6",
"version": "1.0.7",
"description": "Utility for creating mock implementation, defining how Jest mocks should behave",

@@ -21,4 +21,3 @@ "type": "commonjs",

"test:sources:watch": "jest --watch",
"prepublishOnly": "yarn build",
"coverage": "cat coverage/*/lcov.info | codecov"
"prepublishOnly": "npm run build"
},

@@ -43,16 +42,15 @@ "repository": {

"devDependencies": {
"@commitlint/cli": "9.1.1",
"@commitlint/config-conventional": "9.1.1",
"@types/jest": "26.0.7",
"codecov": "3.7.2",
"husky": "4.2.5",
"jest": "26.2.1",
"lint-staged": "10.2.11",
"@arkweid/lefthook": "0.7.7",
"@bhovhannes/shared-config": "0.0.1",
"@commitlint/cli": "14.1.0",
"@rollup/plugin-typescript": "8.3.0",
"@types/jest": "27.0.2",
"jest": "27.3.1",
"npm-run-all": "4.1.5",
"prettier": "2.0.5",
"rollup": "2.23.0",
"rollup-plugin-typescript": "1.0.1",
"ts-jest": "26.1.4",
"typescript": "3.9.7"
"prettier": "2.4.1",
"rollup": "2.59.0",
"ts-jest": "27.0.7",
"tslib": "2.3.1",
"typescript": "4.4.4"
}
}
# jestor
[![NPM version][npm-version-image]][npm-url] [![NPM downloads][npm-downloads-image]][npm-url] [![Dependencies][deps-image]][deps-url] [![Dev. Dependencies][dev-deps-image]][dev-deps-url] [![MIT License][license-image]][license-url] [![Build Status][travis-image]][travis-url] [![Coverage][codecov-image]][codecov-url]
[![NPM version][npm-version-image]][npm-url] [![NPM downloads][npm-downloads-image]][npm-url] [![MIT License][license-image]][license-url] [![Coverage][codecov-image]][codecov-url]

@@ -26,9 +26,7 @@ Utility for creating mock implementations for Jest mocks.

it('should return 4 whan called with 44', function() {
it('should return 4 whan called with 44', function () {
const mock = jest.fn()
// define mock implementation using jestor api
jestor(mock)
.whenCalledWith(44)
.return(4)
jestor(mock).whenCalledWith(44).return(4)

@@ -52,9 +50,7 @@ expect(mock(44)).toBe(4)

it('should return 4 whan called with 44', function() {
it('should return 4 whan called with 44', function () {
const mock = jest.fn()
// whenCalledWith allows to define only a single rule
jestor(mock)
.whenCalledWith(44)
.return(4)
jestor(mock).whenCalledWith(44).return(4)

@@ -68,13 +64,13 @@ expect(mock(44)).toBe(4)

If you want to define multiple rules, `followRules` should be used.
It accepts a function, which should return array of rules, which define what mock should do when the given condition is met:
It accepts a function, which define what mock should do when the given condition is met:
```javascript
it('should allow to define multiple rules', function() {
it('should allow to define multiple rules', function () {
const spy = jest.fn()
jestor(spy).followRules(rules => [
rules.whenCalledWith(1).return(false),
rules.whenCalledWith(2).return(true),
rules.whenCalledWith('foo').resolveWith('foo'),
jestor(spy).followRules((rules) => {
rules.whenCalledWith(1).return(false)
rules.whenCalledWith(2).return(true)
rules.whenCalledWith('foo').resolveWith('foo')
rules.whenCalledWith('bar').rejectWith('bar')
])
})

@@ -87,3 +83,3 @@ expect(spy(1)).toBe(false)

await spy('bar').catch(e => {
await spy('bar').catch((e) => {
expect(e).toBe('bar')

@@ -104,9 +100,7 @@ })

it('should return 6 whan called with 2 and 3', function() {
it('should return 6 whan called with 2 and 3', function () {
const mock = jest.fn()
// whenCalledWith accepts multiple arguments
jestor(mock)
.whenCalledWith(2, 3)
.return(6)
jestor(mock).whenCalledWith(2, 3).return(6)

@@ -125,9 +119,7 @@ expect(mock(2, 3)).toBe(6)

it('should return 6 whan called with string and 3', function() {
it('should return 6 whan called with string and 3', function () {
const mock = jest.fn()
// whenCalledWith also accepts expect matchers
jestor(mock)
.whenCalledWith(expect.any(String), 3)
.return(6)
jestor(mock).whenCalledWith(expect.any(String), 3).return(6)

@@ -153,9 +145,7 @@ expect(mock('foo', 3)).toBe(6)

it('should return 6 whan called with string and 3', function() {
it('should return 6 whan called with string and 3', function () {
const mock = jest.fn()
// tell jestor to return 6 when mock is called with 3
jestor(mock)
.whenCalledWith(3)
.return(6)
jestor(mock).whenCalledWith(3).return(6)

@@ -174,3 +164,3 @@ expect(mock(3)).toBe(6)

it('should return resolved promise when resolveWith is used', function() {
it('should return resolved promise when resolveWith is used', function () {
const mock = jest.fn()

@@ -203,11 +193,11 @@

it('should return rejected promise when rejectWith is used', function() {
it('should return rejected promise when rejectWith is used', function () {
const mock = jest.fn()
// tell jestor to return rejected promise
jestor(mock).whenCalledWith(2).rejectWith('failure');
jestor(mock).whenCalledWith(2).rejectWith('failure')
// assert if we really got a promise rejected with 'failure'
const err = await mock(2).catch(e => e);
expect(err).toBe('failure');
const err = await mock(2).catch((e) => e)
expect(err).toBe('failure')
})

@@ -223,14 +213,10 @@ ```

it('should throw an exception when throw is used', function() {
it('should throw an exception when throw is used', function () {
const mock = jest.fn()
// tell jestor to throw
jestor(mock)
.whenCalledWith(2)
.throw('exception')
jestor(mock).whenCalledWith(2).throw('exception')
// assert if we really got an exception
jestor(mock)
.whenCalledWith(2)
.throw('exception')
jestor(mock).whenCalledWith(2).throw('exception')
expect(() => {

@@ -272,10 +258,10 @@ spy(2)

describe('my function', function() {
it('should return a value', function() {
describe('my function', function () {
it('should return a value', function () {
const mock = jest.fn()
jestor(mock).followRules(rules => [
rules.whenCalledWith('Alice').return('human'),
rules.whenCalledWith(expect.any(Number), expect.any(Number)).return('numbers'),
jestor(mock).followRules((rules) => {
rules.whenCalledWith('Alice').return('human')
rules.whenCalledWith(expect.any(Number), expect.any(Number)).return('numbers')
rules.whenCalledWith(expect.any(Function)).return('function')
])
})
})

@@ -288,3 +274,3 @@ })

It should have been named `jester`, as jester is a person who jests.
However the names `jester`, `jestr` and even `jster` have been taken. As well as `mocker` and `jocker`.
However, the names `jester`, `jestr` and even `jster` have been taken. As well as `mocker` and `jocker`.

@@ -295,6 +281,2 @@ ## License

[deps-image]: https://img.shields.io/david/bhovhannes/jestor.svg
[deps-url]: https://david-dm.org/bhovhannes/jestor
[dev-deps-image]: https://img.shields.io/david/dev/bhovhannes/jestor.svg
[dev-deps-url]: https://david-dm.org/bhovhannes/jestor#info=devDependencies
[license-image]: http://img.shields.io/badge/license-MIT-blue.svg?style=flat

@@ -305,5 +287,3 @@ [license-url]: LICENSE

[npm-downloads-image]: https://img.shields.io/npm/dm/jestor.svg?style=flat
[travis-url]: https://travis-ci.com/bhovhannes/jestor
[travis-image]: https://img.shields.io/travis/bhovhannes/jestor.svg?style=flat
[codecov-url]: https://codecov.io/gh/bhovhannes/jestor
[codecov-image]: https://img.shields.io/codecov/c/github/bhovhannes/jestor.svg

@@ -10,3 +10,3 @@ /// <reference types="jest" />

whenCalledWith(...args: any[]): IJestorBehavior;
}) => any[];
}) => unknown;
interface IJestor {

@@ -13,0 +13,0 @@ whenCalledWith(...args: any[]): IJestorBehavior;

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