@salestrip/stub
Advanced tools
Comparing version 1.0.0 to 2.0.0
@@ -0,3 +1,10 @@ | ||
/* eslint no-empty-function: 'off' */ | ||
'use strict' | ||
// 3rd-party | ||
const Bluebird = require('bluebird') | ||
// init | ||
Bluebird.onPossiblyUnhandledRejection(() => {}) | ||
module.exports = function(subject, methodName, value) { | ||
@@ -12,6 +19,6 @@ subject[`_${methodName}`] = subject[methodName] | ||
subject[methodName].resolves = function(results) { | ||
subject[methodName].mockResolvedValue(results) | ||
subject[methodName].mockReturnValue(Bluebird.resolve(results)) | ||
} | ||
subject[methodName].rejects = function(results) { | ||
subject[methodName].mockRejectedValue(results) | ||
subject[methodName].mockReturnValue(Bluebird.reject(results)) | ||
} | ||
@@ -18,0 +25,0 @@ subject[methodName].returns = function(results) { |
@@ -6,3 +6,3 @@ { | ||
"license": "MIT", | ||
"version": "1.0.0", | ||
"version": "2.0.0", | ||
"main": "index.js", | ||
@@ -28,3 +28,5 @@ "author": "SalesTrip Limited", | ||
], | ||
"dependencies": {}, | ||
"dependencies": { | ||
"bluebird": "^3.5.2" | ||
}, | ||
"devDependencies": { | ||
@@ -31,0 +33,0 @@ "@salestrip/eslint-config": "^0.4.0", |
@@ -7,3 +7,3 @@ # @salestrip/stub | ||
## Installation | ||
## Install | ||
@@ -14,4 +14,39 @@ ```bash | ||
## Releasing | ||
## Usage | ||
```js | ||
const stub = require('@salestrip/stub') | ||
const fooService = require('services/foo.service') | ||
beforeEach(() => { | ||
stub(fooService, 'method') | ||
}) | ||
afterEach(() => { | ||
fooService.method.restore() | ||
}) | ||
it('resolves', () => { | ||
fooService.method.resolves('value') | ||
expect(fooService.method()).resolves.toBe('value') | ||
}) | ||
it('rejects', () => { | ||
fooService.method.rejects('value') | ||
expect(fooService.method()).rejects.toBe('value') | ||
}) | ||
it('returns', () => { | ||
fooService.method.returns('value') | ||
expect(fooService.method()).toBe('value') | ||
}) | ||
it('throws', () => { | ||
fooService.method.throws(new Error('value')) | ||
expect(fooService.method()).toThrow('value') | ||
}) | ||
``` | ||
## Release | ||
To release a new version, use npm. Using `npm version` will update the version in `package.json` before committing the resulting file change to git and adding the appropriate git tag. Pushing a tagged version to `origin` will trigger a CI deployment to the npm registry. | ||
@@ -41,1 +76,2 @@ | ||
git push --tags | ||
``` |
'use strict' | ||
// 3rd-party | ||
const Bluebird = require('bluebird') | ||
// local | ||
@@ -45,2 +48,8 @@ const stub = require('../lib/stub') | ||
}) | ||
it('returns Bluebird promise', () => { | ||
const {subject} = this | ||
subject.method.resolves('whatever') | ||
expect(subject.method()).toBeInstanceOf(Bluebird) | ||
}) | ||
}) | ||
@@ -47,0 +56,0 @@ |
Sorry, the diff of this file is not supported yet
8796
10
153
75
1
+ Addedbluebird@^3.5.2
+ Addedbluebird@3.7.2(transitive)