This repository was archived by the owner on Sep 14, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 59
Add expect.extend #142
Merged
benbrimeyer
merged 15 commits into
Roblox:master
from
benbrimeyer:bbrimeyer/feature/extend-expectation
Oct 1, 2020
Merged
Add expect.extend #142
benbrimeyer
merged 15 commits into
Roblox:master
from
benbrimeyer:bbrimeyer/feature/extend-expectation
Oct 1, 2020
Conversation
This file contains hidden or 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
MagiMaster
reviewed
Oct 1, 2020
MagiMaster
reviewed
Oct 1, 2020
MagiMaster
reviewed
Oct 1, 2020
MagiMaster
approved these changes
Oct 1, 2020
MagiMaster
reviewed
Oct 1, 2020
@@ -76,7 +76,9 @@ function Expectation.new(value) | |||
local self = { | |||
value = value, | |||
successCondition = true, | |||
condition = false | |||
condition = false, | |||
matchers = {}, |
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.
Is matchers
used? I don't see it anywhere else.
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.
We use it once when we need to negate our expectation
https://github.com/Roblox/testez/pull/142/files#diff-c51d01b32afee27efe59f26103c1e704R129
We pass in the non-bound versions of the extend config.
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.
Oh, yep. There it is.
MagiMaster
approved these changes
Oct 1, 2020
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Heavily influenced by https://jestjs.io/docs/en/expect#expectextendmatchers
Adds
expect.extend
which allow projects to add their own matchers to TestEZ.Matchers are functions that should return an object with with two keys: boolean
pass
and a stringmessage
This allows use cases to register their own, opinionated expectations that integrates into expect.
Cavets:
Since describe blocks are outside the usual test execution environment and exist primarily for planning, we do not have easy access to the test session's context, making supporting
extend
from describe blocks non-trival.Realistically we may want to consider throwing a helpful error when users attempt to call expect from describe blocks, since these assertions should not occur during planning.
If a custom matcher is over written, we will throw. This is to help catch collisions in larger projects which would otherwise lead to subtle, confusing errors.
If a custom matcher tries to overwrite a default matcher or protected field of Expectation, it will throw.