@salestrip/stub

2.2.1 • Public • Published

@salestrip/stub

Build Status

A simple stub helper for Jest.

Install

npm i -D @salestrip/stub

Usage

const stub = require('@salestrip/stub')
const fooModule = require('modules/foo.module')

beforeEach(() => {
  stub(fooModule, 'method')
})

afterEach(() => {
  fooModule.method.restore()
})

it('resolves', () => {
  fooModule.method.resolves('value')
  return expect(fooModule.method()).resolves.toBe('value')
})

it('resolves once', async () => {
  fooModule.method.resolvesOnce('value')
  await expect(fooModule.method()).resolves.toBe('value')
  expect(fooModule.method()).toBeUndefined()
})

it('rejects', () => {
  fooModule.method.rejects('value')
  return expect(fooModule.method()).rejects.toBe('value')
})

it('rejects once', async () => {
  fooModule.method.rejectsOnce('value')
  await expect(fooModule.method()).rejects.toBe('value')
  expect(fooModule.method()).toBeUndefined()
})

it('returns', () => {
  fooModule.method.returns('value')
  expect(fooModule.method()).toBe('value')
})

it('returns once', () => {
  fooModule.method.returnsOnce('value')
  expect(fooModule.method()).toBe('value')
  expect(fooModule.method()).toBeUndefined()
})

it('throws', () => {
  fooModule.method.throws(new Error('value'))
  expect(fooModule.method()).toThrow('value')
})

it('throws once', () => {
  fooModule.method.throwsOnce(new Error('value'))
  expect(fooModule.method()).toThrow('value')
  expect(fooModule.method()).toBeUndefined()
})

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.

To release a bugfix update the patch version.

npm version patch
git push
git push --tags

To release a feature update the minor version.

npm version minor
git push
git push --tags

To release a breaking change update the major version.

npm version major
git push
git push --tags

Readme

Keywords

Package Sidebar

Install

npm i @salestrip/stub

Weekly Downloads

1

Version

2.2.1

License

MIT

Unpacked Size

17.1 kB

Total Files

14

Last publish

Collaborators

  • srivai.vignesh
  • gmanojkumar
  • jmelville
  • vinodkrsalestrip
  • hemanthstrip