moll / js-must

An assertion library for JavaScript and Node.js with a friendly BDD syntax (awesome.must.be.true()). It ships with many expressive matchers and is test runner and framework agnostic. Follows RFC 2119 with its use of MUST. Good stuff and well tested.
Other
336 stars 35 forks source link

Custom Changes #32

Closed saulshanabrook closed 9 years ago

saulshanabrook commented 9 years ago

Is it currently possible to change the data midway through an assertion?

For example I have a want to resolve a promise (using eventually) then select the value key from the object returned, then convert that JSON string into a JS object, then do a check on it.

moll commented 9 years ago

Hey,

You could do that via any regular way you handle promises. Like:

promise.then((p) => JSON.parse(p.field)).must.then.eql({name: "John"})

Would that work?

saulshanabrook commented 9 years ago

Yep! I would also have to handle if the promise failed, right?

moll commented 9 years ago

Not necessarily. If you pass the whole promise to something that waits on it, it'll blow up if your JSON parsing failed. Must uses the same mechanism — it just rejects the promise if the assertion failed. I wrote a small example here: https://github.com/moll/js-must/issues/22#issuecomment-111840555

saulshanabrook commented 9 years ago

Awesome, thank you!

moll commented 9 years ago

Yippie!