2.2.1 • Published 5 years ago

@salestrip/stub v2.2.1

Weekly downloads
-
License
MIT
Repository
github
Last release
5 years ago

@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
2.2.1

5 years ago

2.2.0

5 years ago

2.1.0

6 years ago

2.0.0

6 years ago

1.0.0

6 years ago

0.1.0

6 years ago