Skip to content

Only first element is tested #77

@ghost

Description

I have noticed that only the first element which is passed to the expect function is tested for the expectation. Example:

it('should fail', function () {
    var divs = $('<div title="a"></div><div title="b"></div>');
    expect(divs).to.have.attr('title', 'a');
});

This test does not fail because only the first div is tested. Since jQuery usually performs operations for every selected element, this was surprise for me.

I don't think the current behaviour should be changed because otherwise it could happen that tests, which fail at the moment because an empty jQuery is passed to expect() would suddenly succeed. However, I think it would be convenient to introduce the each keyword which performs the expectation for every given element. Example:

it('should fail', function () {
    var divs = $('<div title="a"></div><div title="b"></div>');
    expect(divs).each.to.have.attr('title', 'a');
});

What do you think?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions