Explorar o código

Merge pull request #55 from patrickfatrick/patch-1

args in testAction, payload as array, check for no dispatches
Evan You %!s(int64=9) %!d(string=hai) anos
pai
achega
b873adea93
Modificáronse 1 ficheiros con 11 adicións e 8 borrados
  1. 11 8
      docs/en/testing.md

+ 11 - 8
docs/en/testing.md

@@ -63,10 +63,10 @@ const actions = actionsInjector({
 })
 
 // helper for testing action with expected mutations
-const testAction = (action, state, expectedMutations, done) => {
+const testAction = (action, args, state, expectedMutations, done) => {
   let count = 0
   // mock dispatch
-  const dispatch = (name, payload) => {
+  const dispatch = (name, ...payload) => {
     const mutation = expectedMutations[count]
     expect(mutation.name).to.equal(name)
     if (payload) {
@@ -77,16 +77,19 @@ const testAction = (action, state, expectedMutations, done) => {
       done()
     }
   }
-  // call the action with mocked store
-  action({
-    dispatch,
-    state
-  })
+  // call the action with mocked store and arguments
+  action({dispatch, state}, ...args)
+
+  // check if no mutations should have been dispatched
+  if (count === 0) {
+    expect(expectedMutations.length).to.equal(0)
+    done()
+  }
 }
 
 describe('actions', () => {
   it('getAllProducts', done => {
-    testAction(actions.getAllProducts, {}, [
+    testAction(actions.getAllProducts, [], {}, [
       { name: 'REQUEST_PRODUCTS' },
       { name: 'RECEIVE_PRODUCTS', payload: [ /* mocked response */ ] }
     ], done)