This repository has been archived by the owner on Nov 11, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
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
Showing
8 changed files
with
129 additions
and
42 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
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
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
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,16 @@ | ||
export const skipDependentTests = (test) => { | ||
const siblings = test.parent.tests; | ||
const index = siblings.indexOf(test); | ||
siblings.slice(index + 1).forEach((dependant) => { | ||
dependant.pending = true; // eslint-disable-line no-param-reassign | ||
}); | ||
}; | ||
|
||
export const executeCommandWithDependentTests = (test, command) => { | ||
try { | ||
command(); | ||
} catch (error) { | ||
skipDependentTests(test); | ||
throw error; | ||
} | ||
}; |
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
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
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,17 @@ | ||
import invariant from 'invariant'; | ||
import {skipDependentTests} from './mochaHelpers'; | ||
|
||
const createAction = (args) => args[0].apply(null, args.slice(1)); | ||
|
||
export default (actions) => function when() { | ||
invariant(this.store, 'Given must be specified for when'); | ||
|
||
try { | ||
const multiple = Array.isArray(actions[0]); | ||
const actualActions = multiple ? actions.map(createAction) : [createAction(actions)]; | ||
this.store = this.store.apply(...actualActions); | ||
} catch (error) { | ||
skipDependentTests(this.test); | ||
throw error; | ||
} | ||
}; |
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,65 @@ | ||
import {spy} from 'sinon'; | ||
import when from './when'; | ||
|
||
describe('when test creator', () => { | ||
const callTest = (apply, ...actions) => { | ||
const test = when(actions); | ||
test.call({store: {apply}}); | ||
}; | ||
|
||
const createAction = () => ({type: 'SIMPLE_ACTION'}); | ||
const addCharacter = (name, squad) => ({ | ||
type: 'ADD_CHARACTER', | ||
name, | ||
squad, | ||
}); | ||
|
||
it('throws an error when there is no store', () => { | ||
const test = when([createAction]); | ||
(() => test.call({})).should.throw(); | ||
}); | ||
it('applies single action', () => { | ||
const apply = spy(); | ||
callTest(apply, createAction); | ||
|
||
apply.should.have.been.calledOnce(); | ||
apply.should.have.been.calledWith(createAction()); | ||
}); | ||
it('sets the store with applied actions to context', () => { | ||
const updatedStore = {state: 'Store has been updated'}; | ||
const context = {store: {apply: () => updatedStore}}; | ||
when([createAction]).call(context); | ||
context.store.should.equal(updatedStore); | ||
}); | ||
it('applies single action with parameters', () => { | ||
const apply = spy(); | ||
callTest(apply, addCharacter, 'Strings', 4); | ||
|
||
apply.should.have.been.calledOnce(); | ||
apply.should.have.been.calledWith(addCharacter('Strings', 4)); | ||
}); | ||
it('applies multiple actions', () => { | ||
const createAnotherAction = () => ({type: 'ANOTHER_ACTION'}); | ||
const apply = spy(); | ||
callTest(apply, [createAction], [createAnotherAction]); | ||
|
||
apply.should.have.been.calledOnce(); | ||
apply.should.have.been.calledWith(createAction(), createAnotherAction()); | ||
}); | ||
it('applies multiple actions with parameters', () => { | ||
const apply = spy(); | ||
callTest( | ||
apply, | ||
[addCharacter, 'Strings', 4], | ||
[addCharacter, 'Tarr', 4], | ||
); | ||
|
||
apply.should.have.been.calledOnce(); | ||
apply.should.have.been.calledWith(addCharacter('Strings', 4), addCharacter('Tarr', 4)); | ||
}); | ||
|
||
it('skips dependent tests when action cannot be created'); | ||
it('skips dependent tests when action cannot be applied'); | ||
it('throws error when action cannot be created'); | ||
it('throws error when action cannt be applied'); | ||
}); |