|
1 | 1 | import { describe, test, expect } from 'vitest' |
2 | | -import { compareNumbers, compareText, compareTextWithArray } from '../src/utils.js' |
| 2 | +import { compareNumbers, compareObject, compareText, compareTextWithArray } from '../src/utils.js' |
3 | 3 |
|
4 | 4 | describe('utils', () => { |
5 | 5 | describe('compareText', () => { |
@@ -135,4 +135,27 @@ describe('utils', () => { |
135 | 135 | expect(compareNumbers(actual, { lte, gte })).toBe(false) |
136 | 136 | }) |
137 | 137 | }) |
| 138 | + |
| 139 | + describe('compareObject', () => { |
| 140 | + test('should pass if the objects are equal', () => { |
| 141 | + expect(compareObject({ 'foo': 'bar' }, { 'foo': 'bar' }).result).toBe(true) |
| 142 | + }) |
| 143 | + |
| 144 | + test('should pass if the objects are deep equal', () => { |
| 145 | + expect(compareObject({ 'foo': { 'bar': 'baz' } }, { 'foo': { 'bar': 'baz' } }).result).toBe(true) |
| 146 | + }) |
| 147 | + |
| 148 | + test('should fail if the objects are not equal', () => { |
| 149 | + expect(compareObject({ 'foo': 'bar' }, { 'baz': 'quux' }).result).toBe(false) |
| 150 | + }) |
| 151 | + |
| 152 | + test('should fail if the objects are only shallow equal', () => { |
| 153 | + expect(compareObject({ 'foo': { 'bar': 'baz' } }, { 'foo': { 'baz': 'quux' } }).result).toBe(false) |
| 154 | + }) |
| 155 | + |
| 156 | + test('should fail if the actual value is a number or array', () => { |
| 157 | + expect(compareObject(10, { 'foo': 'bar' }).result).toBe(false) |
| 158 | + expect(compareObject([{ 'foo': 'bar' }], { 'foo': 'bar' }).result).toBe(false) |
| 159 | + }) |
| 160 | + }) |
138 | 161 | }) |
0 commit comments