-
Notifications
You must be signed in to change notification settings - Fork 110
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4cbfbd1
commit 05e767b
Showing
2 changed files
with
45 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { Component } from './component' | ||
import { Controller } from './controller' | ||
|
||
it('can reset component', async () => { | ||
const c = new Component() | ||
const controller = new Controller({ root: c }) | ||
|
||
const c_prepare = jest.fn() | ||
const c_run = jest.fn() | ||
const c_end = jest.fn() | ||
const c_reset = jest.fn() | ||
c.on('prepare', c_prepare) | ||
c.on('run', c_run) | ||
c.on('end', c_end) | ||
c.on('reset', c_reset) | ||
|
||
// We are testing that the component can be re-run, | ||
// and cycles through run and end events correctly | ||
await controller.run() | ||
expect(c_prepare).toHaveBeenCalledTimes(1) | ||
expect(c_run).toHaveBeenCalledTimes(1) | ||
expect(c_end).toHaveBeenCalledTimes(0) | ||
expect(c_reset).toHaveBeenCalledTimes(0) | ||
await c.reset() | ||
expect(c_run).toHaveBeenCalledTimes(2) | ||
expect(c_end).toHaveBeenCalledTimes(1) | ||
expect(c_reset).toHaveBeenCalledTimes(1) | ||
await c.respond('foo', { timestamp: 123, action: 'someAction' }) | ||
expect(c_run).toHaveBeenCalledTimes(2) | ||
expect(c_end).toHaveBeenCalledTimes(2) | ||
// Preparation should only happen once | ||
expect(c_prepare).toHaveBeenCalledTimes(1) | ||
expect(c_reset).toHaveBeenCalledTimes(1) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters