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

I was expecting to expect 2 arrays of objects to be the same, but they're not #57

Open
JimBarrows opened this issue Nov 14, 2016 · 1 comment

Comments

@JimBarrows
Copy link

JimBarrows commented Nov 14, 2016

I was expecting this to return true. The only difference I can see is that the fields are in a different order. Is there something I'm missing?

expect([{
		__v: 0,
		name: 'First one',
		owner: "582a4aac593bdac822a535b6",
		_id: "582a4aad593bdac822a535b7",
		size: 0,
		cards: []
	},
	{
		__v: 0,
		name: 'SecondOne',
		owner: "582a4aac593bdac822a535b6",
		_id: "582a4aad593bdac822a535b8",
		size: 0,
		cards: []
	}
]).to.include.all.that.deep.equals([
	{
		_id: '582a4aad593bdac822a535b7',
		name: 'First one',
		owner: '582a4aac593bdac822a535b6',
		__v: 0,
		size: 0,
		cards: []
	},
	{
		_id: '582a4aad593bdac822a535b8',
		name: 'SecondOne',
		owner: '582a4aac593bdac822a535b6',
		__v: 0,
		size: 0,
		cards: []
	}
]);
@meeber
Copy link

meeber commented Nov 15, 2016

@JimBarrows It doesn't look like chai-things supports what you're trying to do. The all flag is for testing that each element in the target array passes a given assertion. For example:

[4, 11, 15].should.all.be.below(20);  // Tests that each element in the array is below 20.

The good news is that in the upcoming Chai v4, the members assertion supports the deep flag. So you can accomplish your goal with just base Chai. It's available right now on npm as [email protected] if you want to give it a shot.

Here's how it'd look with base Chai v4:

expect([{
        __v: 0,
        name: 'First one',
        owner: "582a4aac593bdac822a535b6",
        _id: "582a4aad593bdac822a535b7",
        size: 0,
        cards: []
    },
    {
        __v: 0,
        name: 'SecondOne',
        owner: "582a4aac593bdac822a535b6",
        _id: "582a4aad593bdac822a535b8",
        size: 0,
        cards: []
    }
]).to.have.deep.members([
    {
        _id: '582a4aad593bdac822a535b7',
        name: 'First one',
        owner: '582a4aac593bdac822a535b6',
        __v: 0,
        size: 0,
        cards: []
    },
    {
        _id: '582a4aad593bdac822a535b8',
        name: 'SecondOne',
        owner: '582a4aac593bdac822a535b6',
        __v: 0,
        size: 0,
        cards: []
    }
]);

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