Skip to content

Fix undefined target element does not throw (fix for issue #2186)#2200

Open
eliasdawson-addepar wants to merge 1 commit intomainmatter:masterfrom
eliasdawson-addepar:undefined-exists-issue-2186
Open

Fix undefined target element does not throw (fix for issue #2186)#2200
eliasdawson-addepar wants to merge 1 commit intomainmatter:masterfrom
eliasdawson-addepar:undefined-exists-issue-2186

Conversation

@eliasdawson-addepar
Copy link
Copy Markdown

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:
#2186

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants