diff --git a/commands/__tests__/create.test.ts b/commands/__tests__/create.test.ts index 0f852cc4c..93aaa4fcd 100644 --- a/commands/__tests__/create.test.ts +++ b/commands/__tests__/create.test.ts @@ -1,10 +1,14 @@ -// @ts-nocheck -import yargs from 'yargs'; +import yargs, { Argv } from 'yargs'; +import createCommand from '../create'; jest.mock('yargs'); -// Import this last so mocks apply -import createCommand from '../create'; +const positionalSpy = jest + .spyOn(yargs as Argv, 'positional') + .mockReturnValue(yargs as Argv); +const optionSpy = jest + .spyOn(yargs as Argv, 'option') + .mockReturnValue(yargs as Argv); describe('commands/create', () => { describe('command', () => { @@ -21,27 +25,27 @@ describe('commands/create', () => { describe('builder', () => { it('should support the correct positional arguments', () => { - createCommand.builder(yargs); + createCommand.builder(yargs as Argv); - expect(yargs.positional).toHaveBeenCalledTimes(3); - expect(yargs.positional).toHaveBeenCalledWith( + expect(positionalSpy).toHaveBeenCalledTimes(3); + expect(positionalSpy).toHaveBeenCalledWith( 'type', expect.objectContaining({ type: 'string' }) ); - expect(yargs.positional).toHaveBeenCalledWith( + expect(positionalSpy).toHaveBeenCalledWith( 'name', expect.objectContaining({ type: 'string' }) ); - expect(yargs.positional).toHaveBeenCalledWith( + expect(positionalSpy).toHaveBeenCalledWith( 'dest', expect.objectContaining({ type: 'string' }) ); }); it('should support the correct options', () => { - createCommand.builder(yargs); + createCommand.builder(yargs as Argv); - expect(yargs.option).toHaveBeenCalledWith( + expect(optionSpy).toHaveBeenCalledWith( 'internal', expect.objectContaining({ type: 'boolean', hidden: true }) ); diff --git a/commands/__tests__/function.test.ts b/commands/__tests__/function.test.ts index 25a009d50..b22ca351e 100644 --- a/commands/__tests__/function.test.ts +++ b/commands/__tests__/function.test.ts @@ -1,19 +1,21 @@ -// @ts-nocheck -import yargs from 'yargs'; +import yargs, { Argv } from 'yargs'; import list from '../function/list'; import deploy from '../function/deploy'; import server from '../function/server'; +import functionCommands from '../function'; jest.mock('yargs'); jest.mock('../function/list'); jest.mock('../function/deploy'); jest.mock('../function/server'); jest.mock('../../lib/commonOpts'); -yargs.command.mockReturnValue(yargs); -yargs.demandCommand.mockReturnValue(yargs); -// Import this last so mocks apply -import functionCommands from '../function'; +const commandSpy = jest + .spyOn(yargs as Argv, 'command') + .mockReturnValue(yargs as Argv); +const demandCommandSpy = jest + .spyOn(yargs as Argv, 'demandCommand') + .mockReturnValue(yargs as Argv); describe('commands/function', () => { describe('command', () => { @@ -29,31 +31,27 @@ describe('commands/function', () => { }); describe('builder', () => { - const subcommands = [ - ['list', list], - ['deploy', deploy], - ['server', server], - ]; + const subcommands = [list, deploy, server]; it('should demand the command takes one positional argument', () => { - functionCommands.builder(yargs); + functionCommands.builder(yargs as Argv); - expect(yargs.demandCommand).toHaveBeenCalledTimes(1); - expect(yargs.demandCommand).toHaveBeenCalledWith(1, ''); + expect(demandCommandSpy).toHaveBeenCalledTimes(1); + expect(demandCommandSpy).toHaveBeenCalledWith(1, ''); }); it('should support the correct options', () => { - functionCommands.builder(yargs); + functionCommands.builder(yargs as Argv); }); it('should add the correct number of sub commands', () => { - functionCommands.builder(yargs); - expect(yargs.command).toHaveBeenCalledTimes(subcommands.length); + functionCommands.builder(yargs as Argv); + expect(commandSpy).toHaveBeenCalledTimes(subcommands.length); }); - it.each(subcommands)('should attach the %s subcommand', (name, module) => { - functionCommands.builder(yargs); - expect(yargs.command).toHaveBeenCalledWith(module); + it.each(subcommands)('should attach the %s subcommand', module => { + functionCommands.builder(yargs as Argv); + expect(commandSpy).toHaveBeenCalledWith(module); }); }); });