Skip to content

New toBeVisible custom matcher #7

@gnapse

Description

@gnapse

As discussed in #4, this library needs a .toBeVisible custom matcher. It operates on an element, receives no extra arguments, and passes if the element is visible to the user.

expect(element).toBeVisible()

How?

This should be implemented by checking the element's computed style, and make sure that display is not none, and also visibility is not hidden or collapsed.

Why?

Doing the equivalent assertion using vanilla DOM APIs is cumbersome:

// Two assertions needed, both dealing with verbose APIs
expect(getComputedStyle(element).getPropertyValue('display')).not.toEqual('none')
expect(getComputedStyle(element).getPropertyValue('visibility')).not.toMatch(/(hidden|collapsed)/)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions