Add some examples for strict equality
This commit is contained in:
24
examples/strictly-speaking/package.json
Normal file
24
examples/strictly-speaking/package.json
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
{
|
||||||
|
"name": "strictly-speaking",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"type": "module",
|
||||||
|
"scripts": {
|
||||||
|
"start": "vitest --ui",
|
||||||
|
"test": "vitest"
|
||||||
|
},
|
||||||
|
"repository": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "git+https://github.com/stevekinney/testing-javascript.git"
|
||||||
|
},
|
||||||
|
"author": "Steve Kinney <hello@stevekinney.net>",
|
||||||
|
"license": "MIT",
|
||||||
|
"bugs": {
|
||||||
|
"url": "https://github.com/stevekinney/testing-javascript/issues"
|
||||||
|
},
|
||||||
|
"homepage": "https://github.com/stevekinney/testing-javascript#readme",
|
||||||
|
"devDependencies": {
|
||||||
|
"@vitest/ui": "^2.1.1",
|
||||||
|
"vite": "^5.4.5",
|
||||||
|
"vitest": "^2.1.1"
|
||||||
|
}
|
||||||
|
}
|
||||||
31
examples/strictly-speaking/strictly-speaking.test.js
Normal file
31
examples/strictly-speaking/strictly-speaking.test.js
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
import { test, expect } from 'vitest';
|
||||||
|
|
||||||
|
class Person {
|
||||||
|
constructor(name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
test('objects with the same properties are equal', () => {
|
||||||
|
expect({ a: 1, b: 2 }).toEqual({ a: 1, b: 2 });
|
||||||
|
});
|
||||||
|
|
||||||
|
test('objects with different properties are not equal', () => {
|
||||||
|
expect({ a: 1, b: 2 }).not.toEqual({ a: 1, b: 3 });
|
||||||
|
});
|
||||||
|
|
||||||
|
test('objects with undefined properties are equal to objects without those properties', () => {
|
||||||
|
expect({ a: 1 }).toEqual({ a: 1, b: undefined });
|
||||||
|
});
|
||||||
|
|
||||||
|
test('objects with undefined properties are *not* strictly equal to objects without those properties', () => {
|
||||||
|
expect({ a: 1 }).not.toStrictEqual({ a: 1, b: undefined });
|
||||||
|
});
|
||||||
|
|
||||||
|
test('instances are equal to object literals with the same properties', () => {
|
||||||
|
expect(new Person('Alice')).toEqual({ name: 'Alice' });
|
||||||
|
});
|
||||||
|
|
||||||
|
test('instances are not strictly equal to object literals with the same properties', () => {
|
||||||
|
expect(new Person('Alice')).not.toStrictEqual({ name: 'Alice' });
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user