forked from moll/js-must
-
Notifications
You must be signed in to change notification settings - Fork 0
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
Fulfill or betray promises #1
Open
jandockx
wants to merge
28
commits into
jandppw:master
Choose a base branch
from
jandockx:fulfill_or_betray_promises
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Conversation
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
…hat should pass - added an actual to error reporting
Promise definition copied from https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/es6-shim/index.d.ts
…stack trace for fulfill and betray
…hen there is no condition nop is not needed
…sted against either)
…iling - changed implementation of betray to avoid exception cycle, and added actual to assert error
the reason was a badly placed (pair of) braces
promise now returns the promise, if it is one
jandockx
force-pushed
the
fulfill_or_betray_promises
branch
from
August 31, 2017 20:13
f4b2d64
to
0117313
Compare
the reason for the failure is that the actual error message we expect is tested this contains a stringified version of this.actual (NOT opts.actual) - see Must.prototype.assert, `var msg = stringify(this.actual) + …` in this case, the actual is a Promise in the node 0.10 version, and only there, this is an object with strange properties `"_40", "_65", "_55", "_72"`, while in other versions of Node this is just an object with then and catch methods these properties are probably private Promise administration, that is exposed the existing Promise tests don't reveal this, because the only place where a Promise is stringified as actual in an assert call in the tests, is in the test for 'must.NOT.be.a.promise()', and there a crafted object is used, not a 'real' Promise the heart of the matter is thus the stringification of a Promise, which is nonsensical in all Node versions ('{}'), does not take into account the Node 0.10 weirdness, and is not really tested with the existing tests fixing this would require a change in Must.prototype.assert, which is a different issue
…calling stringify in test, and compare literally a better representation of this.actual in Must.prototype.assert would be a better solution, but is independent of this
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I recently switched to must from chai, because I started to used Standardjs.
I do find the reasons why you created must meaningful ("Beware of libraries that assert
on property access", "RFC 2119", …), and find myself happier with must than chai.
In both cases, I am frustrated with testing Promises.
The current
must.resolve
andmust.reject
primitives lead me to complex codingstructures, embedded in Promise.all([]) constructs far to often (the same applies to chai
and its extensions).
This is an example of a Mocha test:
Note that the
initialised.must.reject
phrase doesn't work. There is no simple way toexpress that an AssertionError should be thrown when the promise resolves, without
doing something with this (
initialised.must.reject.to…
). To work, we would needsomething of the form
initialised.must.reject()
, i.e., a method call.If I want to say more about the returned value or error, and about the state of other
things after the promise settles, I seem to be forced to use complex Promise.all([])
constructs, and variables to store intermediate results.
In this PR, I offer an alternative that seems to work in my tests. We express that
a Promise must 'fulfill' or 'betrays' its intentions. The check fails if the Promise
does not settle in the way it must. If it does, the conditions that we express in
the 'fullfil' or 'betray' argument are tested.
The whole can be returned in a test, which is the most pleasing way most test frameworks
support asynchronous tests.
With these new methods, the above test now becomes:
There is much less accidental complexity in this form.
More examples are in the JS Doc.
I you find to time, it would be nice if you could review this solution, and give me
any feedback that you deem relevant.