diff --git a/test/specs/commands/view/CommandAbstract.ts b/test/specs/commands/view/CommandAbstract.ts index b05105a14..12da6f389 100644 --- a/test/specs/commands/view/CommandAbstract.ts +++ b/test/specs/commands/view/CommandAbstract.ts @@ -1,3 +1,4 @@ +import CommandsEvents from '../../../../src/commands/types'; import CommandAbstract from '../../../../src/commands/view/CommandAbstract'; import Editor from '../../../../src/editor'; @@ -17,11 +18,15 @@ describe('CommandAbstract', () => { const runSpy = jest.spyOn(command, 'run'); runSpy.mockReturnValue(returnValue as any); const result = command.callRun(editor); - - expect(triggerSpy.mock.calls.length).toBe(3); - expect(triggerSpy.mock.calls[0]).toEqual(['run:test:before', {}]); - expect(triggerSpy.mock.calls[1]).toEqual(['run:test', returnValue, {}]); - expect(triggerSpy.mock.calls[2]).toEqual(['run', 'test', returnValue, {}]); + const options = {}; + const resOptions = { options, id: command.id, result: returnValue }; + expect(triggerSpy.mock.calls.length).toBe(6); + expect(triggerSpy.mock.calls[0]).toEqual([`${CommandsEvents.runBeforeCommand}test`, { options }]); + expect(triggerSpy.mock.calls[1]).toEqual(['run:test:before', options]); + expect(triggerSpy.mock.calls[2]).toEqual([`${CommandsEvents.runCommand}test`, resOptions]); + expect(triggerSpy.mock.calls[3]).toEqual([CommandsEvents.run, resOptions]); + expect(triggerSpy.mock.calls[4]).toEqual(['run:test', returnValue, options]); + expect(triggerSpy.mock.calls[5]).toEqual(['run', 'test', returnValue, options]); expect(runSpy).toBeCalledTimes(1); expect(result).toEqual(returnValue); @@ -29,15 +34,17 @@ describe('CommandAbstract', () => { test('callRun returns undefined when "abort" option is specified', () => { const returnValue = 'result'; - const opts = { abort: true }; + const options = { abort: true }; const triggerSpy = jest.spyOn(editor, 'trigger'); const runSpy = jest.spyOn(command, 'run'); runSpy.mockReturnValue(returnValue as any); - const result = command.callRun(editor, opts); + const result = command.callRun(editor, options); - expect(triggerSpy.mock.calls.length).toBe(2); - expect(triggerSpy.mock.calls[0]).toEqual(['run:test:before', opts]); - expect(triggerSpy.mock.calls[1]).toEqual(['abort:test', opts]); + expect(triggerSpy.mock.calls.length).toBe(4); + expect(triggerSpy.mock.calls[0]).toEqual([`${CommandsEvents.runBeforeCommand}test`, { options }]); + expect(triggerSpy.mock.calls[1]).toEqual(['run:test:before', options]); + expect(triggerSpy.mock.calls[2]).toEqual([`${CommandsEvents.abort}test`, { options }]); + expect(triggerSpy.mock.calls[3]).toEqual(['abort:test', options]); expect(runSpy).toBeCalledTimes(0); expect(result).toEqual(undefined); @@ -49,11 +56,16 @@ describe('CommandAbstract', () => { const runSpy = jest.spyOn(command, 'stop'); runSpy.mockReturnValue(returnValue as any); const result = command.callStop(editor); + const options = {}; + const resOptions = { options, id: command.id, result: returnValue }; - expect(triggerSpy.mock.calls.length).toBe(3); - expect(triggerSpy.mock.calls[0]).toEqual(['stop:test:before', {}]); - expect(triggerSpy.mock.calls[1]).toEqual(['stop:test', returnValue, {}]); - expect(triggerSpy.mock.calls[2]).toEqual(['stop', 'test', returnValue, {}]); + expect(triggerSpy.mock.calls.length).toBe(6); + expect(triggerSpy.mock.calls[0]).toEqual([`${CommandsEvents.stopBeforeCommand}test`, { options }]); + expect(triggerSpy.mock.calls[1]).toEqual(['stop:test:before', options]); + expect(triggerSpy.mock.calls[2]).toEqual([`${CommandsEvents.stopCommand}test`, resOptions]); + expect(triggerSpy.mock.calls[3]).toEqual([CommandsEvents.stop, resOptions]); + expect(triggerSpy.mock.calls[4]).toEqual(['stop:test', returnValue, options]); + expect(triggerSpy.mock.calls[5]).toEqual(['stop', 'test', returnValue, options]); expect(runSpy).toBeCalledTimes(1); expect(result).toEqual(returnValue);