Skip to content

Instantly share code, notes, and snippets.

@0ex-d
Created August 3, 2021 07:21
Show Gist options
  • Save 0ex-d/c56fe279655991994cb8f22a57492ed0 to your computer and use it in GitHub Desktop.
Save 0ex-d/c56fe279655991994cb8f22a57492ed0 to your computer and use it in GitHub Desktop.
describe("Referential Equality", () => {
function foo() {
return 'bar';
}
const otherFoo = function() {
return `bar`;
};
const anotherFoo = () => 'bar';
describe("Loose Equality", () => {
test('Compare two strings',() => {
const point_a = 'hello'
const point_b = 'hello'
expect(point_a==point_b).toBeTruthy();
});
test('Compare fn',() => {
expect(foo==otherFoo).toBeFalsy();
});
test('two distinct objects are never equal',() => {
const point_a = {}
const point_b = {}
expect(point_a==point_b).toBeFalsy();
});
});
describe("Object Equality", () => {
test('Compare Objects',() => {
let point_a = {}
let point_b = {}
expect(Object.is(point_a, point_b)).toBeFalsy();
});
});
describe("Strict Equality", () => {
const fooReference = foo;
test('Commpare two strings',() => {
const point_a = 'hello'
const point_b = 'hello'
expect(point_a===point_b).toBeTruthy();
});
test('Compare same fn definition',() => {
expect(foo===foo).toBeTruthy();
});
test('Compare same return value but different defs fn',() => {
expect(foo===otherFoo).toBeFalsy();
});
test('Compare fn',() => {
expect(foo===anotherFoo).toBeFalsy();
});
test('Compare fn and referenced var',() => {
expect(foo === fooReference).toBeTruthy();
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment