/
githubmirror
/
client
Обзор
Документация
Войти
/
githubmirror
/
client
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
shared/util/shallow-equal.test.ts
50 строк
1 KB
chrisnojima-zoom
Version 670 - clean2 (#29122)
08 июн 2026, 19:31
Не верифицирован
08 июн 2026, 19:31
1943197
Код
Авторство
О чём код?
/// <reference types="jest" /> import shallowEqual from './shallow-equal' test('returns true for the same reference', () => { const value = {a: 1} expect(shallowEqual(value, value)).toBe(true) }) test('uses strict equality for primitives and rejects null/object mismatches', () => { expect(shallowEqual(null, {})).toBe(false) expect(shallowEqual({}, null)).toBe(false) expect(shallowEqual(1, 1)).toBe(true) expect(shallowEqual(1, 2)).toBe(false) expect(shallowEqual(1, {})).toBe(false) }) test('compares arrays shallowly', () => { expect(shallowEqual([1, 2], [1, 2])).toBe(true) expect(shallowEqual([1, {nested: true}], [1, {nested: true}])).toBe(false) }) test('only compares own enumerable keys', () => { const proto = {shared: 1} const a = Object.create(proto) as {local?: number} const b = Object.create(proto) as {local?: number} a.local = 2 b.local = 2 expect(shallowEqual(a, b)).toBe(true) const withOwnShared = {local: 2, shared: 1} expect(shallowEqual(a, withOwnShared)).toBe(false) }) test('ignores non-enumerable properties', () => { const a = {visible: 1} const b = {visible: 1} Object.defineProperty(a, 'hidden', {enumerable: false, value: 1}) Object.defineProperty(b, 'hidden', {enumerable: false, value: 2}) expect(shallowEqual(a, b)).toBe(true) }) test('uses strict equality for leaf values', () => { expect(shallowEqual({a: Number.NaN}, {a: Number.NaN})).toBe(false) expect(shallowEqual({a: undefined}, {a: undefined})).toBe(true) })