Skip to content

Commit

Permalink
expose setupCommandTest
Browse files Browse the repository at this point in the history
  • Loading branch information
unional committed Nov 19, 2017
1 parent 41e32ed commit afbac6d
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 10 deletions.
8 changes: 8 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@
"@types/fbemitter": "^2.0.32",
"fbemitter": "^2.1.1",
"flux-standard-action": "^2.0.0",
"lodash.merge": "^4.6.0"
"lodash.merge": "^4.6.0",
"unpartial": "^0.4.1"
},
"devDependencies": {
"@types/node": "^8.0.53",
Expand Down
10 changes: 1 addition & 9 deletions src/Command.spec.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,9 @@
import test from 'ava'
import Order from 'assert-order'
import { unpartial } from 'unpartial'
import { createEvent, TestEmitter, CommandConstructor, CommandContext } from './index'
import { createEvent, TestEmitter, setupCommandTest } from './index'

import { Command } from './index'

export function setupCommandTest<Context extends CommandContext, Cmd extends Command>(Command: CommandConstructor<Context, Cmd>, givenContext: Partial<Context> = {}) {
const emitter = new TestEmitter()
const context = unpartial<Context>({ emitter } as any, givenContext)
context.emitter = context.emitter || emitter
const command = new Command(context)
return { emitter, command }
}
test('Command provides emitter to subclass', t => {
const event = createEvent('event')
class TestCommand extends Command {
Expand Down
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ export * from './createEvent'
export * from './createEventAction'
export * from './Emitter'
export * from './errorEvent'
export * from './setupCommandTest'
export * from './TestEmitter'

// This is commented out because likely this occurs in testing only and may be an issue with fbemitter.
Expand Down
12 changes: 12 additions & 0 deletions src/setupCommandTest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { unpartial } from 'unpartial'

import { CommandContext, Command, CommandConstructor } from './Command'
import { TestEmitter } from './TestEmitter'

export function setupCommandTest<Context extends CommandContext, Cmd extends Command>(Command: CommandConstructor<Context, Cmd>, givenContext: Partial<Context> = {}) {
const emitter = new TestEmitter()
const context = unpartial<Context>({ emitter } as any, givenContext)
context.emitter = context.emitter || emitter
const command = new Command(context)
return { emitter, command }
}

0 comments on commit afbac6d

Please sign in to comment.