-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
instances of different classes with same name should not be treated as equal #6767
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
Comments
The constructor is the same in this example. Only difference is ref. |
Ok... More detailed example. @palmerj3 test("", () => {
class Logger{constructor(level: number){}} // some external logger
class XMLParser{constructor(file: string){}} // some external parser
const FooLogger = class Foo extends Logger{};
const FooParser = class Foo extends XMLParser{};
const actual = new FooLogger(1);
const expected = new FooParser("/tmp/1.xml");
expect(actual).toEqual(expected); // pass
expect(actual).toStrictEqual(expected); // pass, but this is two absolutely different objects
expect(actual).toEqual(new Logger(1)); // pass
expect(actual).toStrictEqual(new Logger(1)); // fail, but this is more likely instances than logger and parser
}); |
At this moment export const typeEquality = (a: any, b: any) => {
if (a == null || b == null || a.constructor.name === b.constructor.name) {
return undefined;
}
return false;
}; |
PR welcome! 🙂 Seems reasonable to check the actual constructors a as well. |
@SimenB I've started looking a bit at this and would love some pointers. Would it be sufficient to simply modify Also guessing that it might be a good idea to add/update some test cases 🙂 |
Try it and see if it break any tests :) |
It looks like this issue can be closed. |
Right, thanks! |
Thanks! |
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
🐛 Bug Report
Look at example. We have two different classes but with the same name
Client
.Expected behavior
expect([new MysqlClient()]).toStrictEqual([new HttpClient()]);
should failThe text was updated successfully, but these errors were encountered: