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

Syntax for http response style JSON #25

Closed
Torniojaws opened this issue Oct 2, 2019 · 3 comments
Closed

Syntax for http response style JSON #25

Torniojaws opened this issue Oct 2, 2019 · 3 comments

Comments

@Torniojaws
Copy link

Torniojaws commented Oct 2, 2019

I'm not sure how the syntax should be for this case:

Input:

{
  "success": true,
  "data": [
    { id: 1, value: "Hello", created: "2019-10-02 14:30:00" },
    { id: 2, value: "There", created: "2019-10-02 14:30:00" },
    { id: 3, value: "General", created: "2019-10-02 14:30:00" }
  ]
}

Assert:

expect(res.body).excludingEvery('created').to.eql({
  "success": true,
  "data": [
    { id: 1, value: "Hello" },
    { id: 2, value: "There" },
    { id: 3, value: "General" }
  ]
});

I ended up separating the top level, but I was wondering if there is a way to exclude in a single assert? Perhaps something like .excludingEvery('data.created')?

Separated:

expect(res.body.success).to.eql(true);
expect(res.body.data).excludingEvery('created').to.eql([
    { id: 1, value: "Hello" },
    { id: 2, value: "There" },
    { id: 3, value: "General" }
]);
@mesaugat
Copy link
Owner

mesaugat commented Oct 3, 2019

Perhaps something like .excludingEvery('data.created')?

@Torniojaws There's no way to do this currently. From what I see, you are doing it correctly by separating the assertions.

@mesaugat
Copy link
Owner

mesaugat commented Oct 3, 2019

Also, @Torniojaws you can keep the created key in your result and chai-exclude will still ignore the key from comparison.

expect(res.body.data).excludingEvery('created').to.eql([
    { id: 1, value: "Hello", created: "2019-10-02 14:30:00" },
    { id: 2, value: "There", created: "2019-10-02 14:30:00" },
    { id: 3, value: "General", created: "2019-10-02 14:30:00" }
]);

@mesaugat
Copy link
Owner

Closing this issue @Torniojaws, I hope I have answered your question. If there are any updates in the future I'll reply back in this thread.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants