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

Have "match" perform matching of array elements #426

Closed
spemmons opened this issue Apr 13, 2015 · 1 comment
Closed

Have "match" perform matching of array elements #426

spemmons opened this issue Apr 13, 2015 · 1 comment

Comments

@spemmons
Copy link

I have found the following function useful for myself and it would be cool if it -- or something similar -- could be incorporated into the "match" function when an array is involved...

function matchArrays(actual,expected){
    actual.length.should.equal(expected.length);
    for(var index = 0; index < actual.length; index++) {
        if (typeof expected[index] === 'string')
            actual[index].should.eql(expected[index]);
        else
            actual[index].should.match(expected[index]);
    }
};
@keithamus
Copy link
Member

Hey @spemmons thanks for the issue.

To me, it very much looks like you want to look at chai-things which allows assertions such as arrayOfStrings.should.all.match(/foo/).

I'll close this issue for now - if you're not happy with the above answer, feel free to reply and I'll re-open it, or file a new issue.

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

2 participants