-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Manage assertions through a class #2080
Conversation
This changes assertions to be properties on the class. Before, assertions were functions which needed to be bound to the test instance. This led to the fact that snapshot() assertion accessed property which only existed on Test - to compare snapshots. Now, the functions which assertions access are clearly defined as those that need to be implemented by child class. This change also updates how ExecutionContext is created, as well as minor changes to the test/assert.js.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm reluctant to expose the protected methods on the execution context. Folks will discover them and use them and I'd rather they didn't. Perhaps we can utilize a WeakMap instead?
This is a good idea. How about those protected methods on Assertions class? Since ExecutionContext now extends that class, the private methods starting with _ might also be discovered and used. Should those private methods be hidden via WeakMap too? If we hide them, then it is slightly more difficult to extend the base Assertions class, as we would have to pass those private functions to the constructor of Assertions and children classes cannot simply overwrite those methods. |
Now we pass functions to super constructor to hide private functions.
This is pretty close to landing, nice work @qlonik! |
🎉 I'll land #2096 tomorrow and fix the merge conflicts here, and then I'll land this one. |
This changes assertions to be properties on the class. Before,
assertions were functions which needed to be bound to the test instance.
This led to the fact that snapshot() assertion accessed property which
only existed on Test - to compare snapshots. Now, the functions which
assertions access are clearly defined as those that need to be
implemented by child class.
This change also updates how ExecutionContext is created, as well as
minor changes to the test/assert.js.
Additionally, if this was to be changed to typescript, properly typing
_skippable
,_enhanced
and parameters to all assertion functions, we would get type information of all assertions methods ont
for free. Also adding doc comments to all assertions would give documentation which lives near the source code.There are also some minor type related changes:
validateExpectations()
. Instead validateExpectations checks if second argument null or undefined.isPromise()
being used, however it only checks if .then on that object exists and it is a function. So, in those cases that PromiseLike object is cast to Promise with.resolve()
.