You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
classUntypedError{privatereadonlymessage;constructor(message: string){this.message=message;}}classTypedErrorextendsError{constructor(message: string){super(message);}}describe("Error Experimentation",()=>{it("should pass in all of these cases",()=>{// Passexpect(newUntypedError("untyped error no array")).to.deep.equal(newUntypedError("untyped error no array"));// Fail - This is the unexpected part, to me.expect(newTypedError("typed error no array")).to.deep.equal(newTypedError("typed error no array"));// This is closer to what I'm actually trying to test but is fundamentally the same thing.// Passexpect([newUntypedError("untyped error array")]).to.deep.include(newUntypedError("untyped error array"));// Fail - The fact that it's part of an array is probably irrelevant, but I cannot be certain.expect([newTypedError("typed error array")]).to.deep.include(newTypedError("typed error array"));});});
I've been working on this for a couple of days now and have seen some resources / hints regarding Chai basically making the decision that two Errors with different call-stacks are evaluated as different, even if they are the same type and have the same message. So, I think that's what's going on here.
My ask is that the team create some dedicated documentation that explains this (so I can be certain that that's what is actually going on here) and propose some alternatives or provide a rationale on why this type of testing shouldn't work / shouldn't be done.
And, if such documentation does already exist, I apologize for wasting your time, and my feedback would be that, that documentation is hard to find. :)
The text was updated successfully, but these errors were encountered:
Hey @jojenki; Error equality is something that seems to be not implemented in chai right now due to some issues that are listed in #1065. Depending on your situation, you might want to assert on the error properties such as name and message rather than asserting the equality of the error objects themselves.
For the question of documentation, I'm not quite sure what would be the best thing to do. Where did you look for information on this? Maybe we can make a PR to the documentation that you were looking at to add this piece of information.
- Use better error messages with more context.
- Unify their validation logic and share tests.
- Validate also type of the name.
- Refactor node (Script/Category) parser tests for easier future
changes and cleaner test code (using `TestBuilder` to do dirty work in
unified way).
- Add more tests. Custom `Error` properties are compared manually due to
`chai` not supporting deep equality checks (chaijs/chai#1065,
chaijs/chai#1405).
- Use better error messages with more context.
- Unify their validation logic and share tests.
- Validate also type of the name.
- Refactor node (Script/Category) parser tests for easier future
changes and cleaner test code (using `TestBuilder` to do dirty work in
unified way).
- Add more tests. Custom `Error` properties are compared manually due to
`chai` not supporting deep equality checks (chaijs/chai#1065,
chaijs/chai#1405).
Simple working example:
I've been working on this for a couple of days now and have seen some resources / hints regarding Chai basically making the decision that two Errors with different call-stacks are evaluated as different, even if they are the same type and have the same message. So, I think that's what's going on here.
My ask is that the team create some dedicated documentation that explains this (so I can be certain that that's what is actually going on here) and propose some alternatives or provide a rationale on why this type of testing shouldn't work / shouldn't be done.
And, if such documentation does already exist, I apologize for wasting your time, and my feedback would be that, that documentation is hard to find. :)
The text was updated successfully, but these errors were encountered: