Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only first element is tested #77

Open
ghost opened this issue Dec 22, 2015 · 0 comments
Open

Only first element is tested #77

ghost opened this issue Dec 22, 2015 · 0 comments

Comments

@ghost
Copy link

ghost commented Dec 22, 2015

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?

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

No branches or pull requests

0 participants