Skip to content

Commit

Permalink
fix: Handle the case when staged-git-files errors properly (#267)
Browse files Browse the repository at this point in the history
Closes #264
  • Loading branch information
okonet authored Sep 6, 2017
1 parent 18c3d26 commit a8a585a
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions test/runAll.spec.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,25 @@
/* eslint no-console: 0 */

import sgfMock from 'staged-git-files'
import { getConfig } from '../src/getConfig'
import runAll from '../src/runAll'

jest.mock('staged-git-files')

sgfMock.mockImplementation((params, callback) => {
callback(null, [])
})

const packageJson = {
scripts: {
mytask: 'echo "Running task"'
}
}

describe('runAll', () => {
afterEach(() => {
sgfMock.mockClear()
})
it('should throw when invalid config is provided', () => {
expect(() => runAll(packageJson, {})).toThrowErrorMatchingSnapshot()
expect(() => runAll(packageJson)).toThrowErrorMatchingSnapshot()
Expand All @@ -30,4 +40,12 @@ describe('runAll', () => {
expect.assertions(1)
return expect(runAll(packageJson, getConfig({}))).resolves.toEqual('No tasks to run.')
})

it('should reject the promise when staged-git-files errors', () => {
sgfMock.mockImplementation((params, callback) => {
callback('test', undefined)
})
expect.assertions(1)
return expect(runAll(packageJson, getConfig({}))).rejects.toEqual('test')
})
})

0 comments on commit a8a585a

Please sign in to comment.