UNPKG

@interaktiv/dia-scripts

Version:

CLI toolbox with common scripts for most sort of projects at DIA

43 lines (37 loc) 1.33 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends")); jest.mock('commitizen/dist/cli/git-cz', () => ({ bootstrap: jest.fn(() => {}) })); jest.mock('../utils', () => (0, _extends2.default)({}, jest.requireActual('../utils'), { isOptedIn: jest.fn(() => true) })); let bootstrapMock, isOptedInMock, originalExit; describe('prepare-commit-msg hook', () => { beforeEach(() => { ({ bootstrap: bootstrapMock } = require('commitizen/dist/cli/git-cz')); originalExit = process.exit; process.exit = jest.fn(); }); afterEach(() => { process.exit = originalExit; jest.resetModules(); }); it('should be called with --hook argument if opted in', () => { require('./prepare-commit-msg'); expect(bootstrapMock).toBeCalledTimes(1); expect(bootstrapMock.mock.calls[0][1]).toEqual(expect.arrayContaining(['--hook'])); }); it('should not be called if not opted in', () => { ({ isOptedIn: isOptedInMock } = require('../utils')); isOptedInMock.mockImplementation(key => key !== 'prepare-commit-msg'); require('./prepare-commit-msg'); expect(process.exit).toBeCalledWith(0); expect(bootstrapMock).toBeCalledTimes(0); }); });