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

exclude property path #9

Closed
mathroc opened this issue Jan 12, 2018 · 6 comments
Closed

exclude property path #9

mathroc opened this issue Jan 12, 2018 · 6 comments

Comments

@mathroc
Copy link
Contributor

mathroc commented Jan 12, 2018

sometime I might want to ignore properties only at certain level, eg:

expect({
  id: 123,
  a: {
    id: 345,
    b: "c",
  }
}).excludingPath(["a", "id"]).to.deep.equals({
  id: 123,
  a: {
    b: "c",
  }
})

do you think excludingPath would be useful ? I’ve worked around it for now by not testing some properties but I’d like to make a PR sometime if you think that would be useful

@mesaugat
Copy link
Owner

Not really sure how helpful this is going to be. Also, excludingPath['a', 'id'] is hard to understand. Also, how deep should we go?

@mathroc
Copy link
Contributor Author

mathroc commented Jan 14, 2018

I’m not sure I understand so here are a few other examples of what I have in mind :

expect({
  id: 123,
  a: {
    id: 345,
    b: "c",
  }
}).excludingPath(["a"]).to.deep.equals({
  id: 123,
})
expect({
  id: 123,
  a: {
    id: 345,
    b: "c",
    a: {
      id: 678
    }
  }
}).excludingPath(["a", "id"]).to.deep.equals({
  id: 123,
  a: {
    b: "c",
    a: {
      id: 678
    }
  }
})
expect({
  id: 123,
  a: {
    id: 345,
    b: "c",
    a: {
      id: 678
    }
  }
}).excludingPath(["a", "a", "id"]).to.deep.equals({
  id: 123,
  a: {
    id: 456,
    b: "c",
    a: {}
  }
})

just realized that the arguments don’t need to be in an array, a variadic function works well here:

expect({
  id: 123,
  a: {
    id: 345,
    b: "c",
    a: {
      id: 678
    }
  }
}).excludingPath("a", "id").to.deep.equals({
  id: 123,
  a: {
    b: "c",
    a: {
      id: 678
    }
  }
})

does that answer your question ? this is mainly to avoid removing all properties having the same name from the object

@mesaugat
Copy link
Owner

And how do you go about excluding various paths and not one? Maybe an array of strings?

excludingPath(['a', 'b'], ['d', 'e'])

{
  a: {
    b: 'c',
    z: 'y'
  },
  d: {
    e: 'd',
    f: 'g'
  }
}

I feel we are trying to do too much here?

@mathroc
Copy link
Contributor Author

mathroc commented Jan 20, 2018

@mesaugat you can always call excludingPath multiple times to exclude multiple paths, or for the sake of consistency, there could be a excludingPaths

imho, excluding path one at a time is enough so I don’t mind having excludingPaths or not and handling multiple paths in excludingPath or not

I feel we are trying to do too much here?

I don’t want to force anything, if you think this outside the scope of chai-exclude, I’ll just add this into my project until I have time to make another plugin

@mesaugat
Copy link
Owner

My only requirement is that the API should be simple to understand. Feel free to send a pull request and then we can discuss about the code itself.

@mesaugat mesaugat removed the question label Jan 22, 2018
@mesaugat
Copy link
Owner

@mathroc I am closing this issue. Hope you have figured out the solution. If you want to reopen this issue feel free to do so. We can discuss further.

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