Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tape support #28

Closed
adamyonk opened this issue Sep 13, 2016 · 6 comments
Closed

Tape support #28

adamyonk opened this issue Sep 13, 2016 · 6 comments

Comments

@adamyonk
Copy link
Contributor

I can get the tests working with something like this:

test('someThunk', (t) => {
  registerMiddlewares([thunk])
  registerInitialStoreState(buildInitialStoreState(rootReducer))

  const expectedActions = [
    actions...
  ]

  const initialState = {
    ...
  }

  assertions.toDispatchActionsWithState(
    initialState,
    someAction(),
    expectedActions,
    t.end
  )
})

This kind of works, because if something goes wrong in toDispatchActionsWithState, tape catches the thrown error and fails the test run, but it doesn't count the test in the tape output when it's passing, because you never actually assert anything with tape (t.equal, t.deepEqual, etc.). If there was some way to get the output actions of toDispatchActionsWithState, I could do some assertion like this:

  const expectedActions = [
    actions...
  ]

  const initialState = {
    ...
  }

  assertions.toDispatchActionsWithState(
    initialState,
    someAction(),
    expectedActions,
    (actualActions) => {
      t.deepEqual(
         actualActions,
         expectedActions,
         'should run the correct actions'
      )
    }
  )

I saw that you can pass a done and fail function in, but I think that would leave us in the same boat here. I'm not sure that an actual tape integration is necessary, if there is a way to get at the array of the actions that were dispatched and to not have a mismatch throw an error (so it could be handled by equal, deepEqual, and friends.

@dmitry-zaets
Copy link
Member

dmitry-zaets commented Sep 13, 2016

Can you please try to pass tape.pass and tape.fail as done and error callbacks into assertion? Should work in that case.

As I can see from docs, it will generate assertion:

t.fail(msg)
Generate a failing assertion with a message msg.
t.pass(msg)
Generate a passing assertion with a message msg.

@adamyonk
Copy link
Contributor Author

Aha, I didn't know that pass would also increment the count. 👍

Here's what ended up working (don't forget end!):

  assertions.toDispatchActionsWithState(
    { ...state },
    action(),
    [ ...expected ],
    t.pass,
    t.fail
  ).then(t.end)

@dmitry-zaets
Copy link
Member

You can use t.end in then block, or you can use t.plan(n) which is more natural for tape.

@dmitry-zaets
Copy link
Member

After all, would be good to add Tape to list of supported frameworks and add doc for it.

@adamyonk
Copy link
Contributor Author

I'd be happy to start a PR, if that would be helpful to you.

@dmitry-zaets
Copy link
Member

@adamyonk Sure!
would be also good to include tape into the project and by analogy, create tests with tape as we have with other frameworks.

@adamyonk adamyonk mentioned this issue Sep 13, 2016
4 tasks
@dmitry-zaets dmitry-zaets removed the docs label Sep 13, 2016
@dmitry-zaets dmitry-zaets changed the title Add tape support Tape support Sep 13, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants