Skip to content

Commit

Permalink
fixed broken tests
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-jonathan committed Jul 21, 2024
1 parent b34a4e2 commit 1088eb2
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions __tests__/behavioral/Command.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import {

import {
Command,
Operation,
CommandHistory,
} from '@/index'

class LightReceiver {
Expand All @@ -64,8 +64,9 @@ class TurnOnLightCommand implements Command {
this.light = light
}

execute(): void {
execute(): boolean {
this.light.turnOn()
return true
}
}

Expand All @@ -76,24 +77,30 @@ class TurnOffLightCommand implements Command {
this.light = light
}

execute(): void {
execute(): boolean {
this.light.turnOff()
return true
}
}

describe('Command', () => {
it('Command execution', () => {
const op = new Operation()
const commandHistory = new CommandHistory()
const light = new LightReceiver()

op.push(new TurnOnLightCommand(light))
const cmd1 = new TurnOnLightCommand(light)
expect(cmd1.execute()).toBeTruthy()
expect(light.isOn).toBeTruthy()
commandHistory.push(cmd1)

op.push(new TurnOffLightCommand(light))

const cmd2 = new TurnOffLightCommand(light)
expect(cmd2.execute()).toBeTruthy()
expect(light.isOn).toBeFalsy()
commandHistory.push(cmd2)

expect(op.pop()).instanceof(TurnOffLightCommand)
expect(op.pop()).instanceof(TurnOnLightCommand)
expect(op.pop()).toBeUndefined()
expect(commandHistory.pop()).instanceof(TurnOffLightCommand)
expect(commandHistory.pop()).instanceof(TurnOnLightCommand)
expect(commandHistory.pop()).toBeUndefined()
})
})

0 comments on commit 1088eb2

Please sign in to comment.