Fix undefined target element does not throw (fix for issue #2186)#2200
Open
eliasdawson-addepar wants to merge 1 commit intomainmatter:masterfrom
Open
Fix undefined target element does not throw (fix for issue #2186)#2200eliasdawson-addepar wants to merge 1 commit intomainmatter:masterfrom
eliasdawson-addepar wants to merge 1 commit intomainmatter:masterfrom
Conversation
When `assert.dom(undefined)` is called, it
incorrectly defaults to the root element instead
of throwing `TypeError: Unexpected Parameter:
undefined`. This means code like
`assert.dom(findAll('.foo')[0]).exists()` silently
passes even when `.foo` doesn't exist (because
`findAll` returns an empty array, and `array[0]`
is `undefined`).
PR#2107 changed the argument detection logic from
`arguments.length === 0` to `target !== undefined`,
which cannot distinguish between "no argument" and
passing "undefined".
This behavior was not caught by tests because
tests only used mock implementation of assert.dom.
This commit restores the original behavior that
correctly distinguishes passing no arguments and
passing undefined and adds a test to ensure
passing undefined throws an error as expected.
Addresses:
mainmatter#2186
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
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.
When
assert.dom(undefined)is called, it incorrectly defaults to the root element instead of throwingTypeError: Unexpected Parameter: undefined. This means code likeassert.dom(findAll('.foo')[0]).exists()silently passes even when.foodoesn't exist (becausefindAllreturns an empty array, andarray[0]isundefined).PR #2107 changed the argument detection logic from
arguments.length === 0totarget !== undefined, which cannot distinguish between "no argument" and passing "undefined".This behavior was not caught by tests because tests only used mock implementation of
assert.dom.This commit restores the original behavior that correctly distinguishes passing no arguments and passing undefined and adds a test to ensure passing undefined throws an error as expected.
Addresses:
#2186