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

Support custom messages for assertions #17

Open
jfairbank opened this issue Sep 25, 2016 · 3 comments
Open

Support custom messages for assertions #17

jfairbank opened this issue Sep 25, 2016 · 3 comments

Comments

@jfairbank
Copy link
Owner

Most assertions libraries allow you to specify a custom message/label as the last argument. This is tricky for test plan because some effect assertions like call take variable number of arguments. What might work best is an additional method that allows you to set a custom message for the next assertion, or an additional function on each effect assertion.

Something like this:

testSaga(mainSaga)
  .next()
  .labeledAssertion('hello world')
  .call(identity, 41);

// SagaTestError:
// Assertion 1 failed: call effects do not match
// hello world
// 
// Expected
// --------
// { context: null, fn: [Function: identity], args: [ 41 ] }
// 
// Actual
// ------
// { context: null, fn: [Function: identity], args: [ 42 ] }

Or something like this:

testSaga(mainSaga)
  .next()
  .call.labeled('hello world', identity, 41);

// SagaTestError:
// Assertion 1 failed: call effects do not match
// hello world
// 
// Expected
// --------
// { context: null, fn: [Function: identity], args: [ 41 ] }
// 
// Actual
// ------
// { context: null, fn: [Function: identity], args: [ 42 ] }

Other suggestions and ideas are welcome.

@TzviPM
Copy link

TzviPM commented Feb 17, 2017

is it possible to call something that's not a function in redux-saga? Perhaps we could just check if the first argument is a function or a string?

@jfairbank
Copy link
Owner Author

Hi, @omniroot. Thanks for the suggestion, but unfortunately, that wouldn't work for other assertions like take which actually can take a string as the first argument. We could create a function that creates a special object for messages via a helper function, but I'm not a big fan of that.

testSaga(mainSaga)
  .next()
  .call(identity, 41, assertionMessage('hello world'));

I'm still leaning toward either of the former ideas I proposed, but this feature has been low priority compared to other features at the moment.

@0xdevalias
Copy link

0xdevalias commented Apr 26, 2019

How about using Symbol()? Iterate over the params (or take the last one), and only if it matches the Symbol, treat it as a message.

Edit: Which reading properly.. is similar to your above wrapping function method..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants