@tanstack/react-store 0.1.3 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tanstack/react-store",
3
3
  "author": "Tanner Linsley",
4
- "version": "0.1.3",
4
+ "version": "0.2.0",
5
5
  "license": "MIT",
6
6
  "repository": "tanstack/react-store",
7
7
  "homepage": "https://tanstack.com/",
@@ -2,7 +2,7 @@ import { render, waitFor } from '@testing-library/react'
2
2
  import '@testing-library/jest-dom'
3
3
  import * as React from 'react'
4
4
  import { Store } from '@tanstack/store'
5
- import { useStore } from '../index'
5
+ import { useStore, shallow } from '../index'
6
6
  import { useState } from 'react'
7
7
  import userEvent from '@testing-library/user-event'
8
8
 
@@ -77,3 +77,56 @@ describe('useStore', () => {
77
77
  expect(getByText('Number rendered: 2')).toBeInTheDocument()
78
78
  })
79
79
  })
80
+
81
+ describe('shallow', () => {
82
+ test('should return true for shallowly equal objects', () => {
83
+ const objA = { a: 1, b: 'hello' }
84
+ const objB = { a: 1, b: 'hello' }
85
+ expect(shallow(objA, objB)).toBe(true)
86
+ })
87
+
88
+ test('should return false for objects with different values', () => {
89
+ const objA = { a: 1, b: 'hello' }
90
+ const objB = { a: 2, b: 'world' }
91
+ expect(shallow(objA, objB)).toBe(false)
92
+ })
93
+
94
+ test('should return false for objects with different keys', () => {
95
+ const objA = { a: 1, b: 'hello' }
96
+ const objB = { a: 1, c: 'world' }
97
+ // @ts-ignore
98
+ expect(shallow(objA, objB)).toBe(false)
99
+ })
100
+
101
+ test('should return false for objects with different structures', () => {
102
+ const objA = { a: 1, b: 'hello' }
103
+ const objB = [1, 'hello']
104
+ // @ts-ignore
105
+ expect(shallow(objA, objB)).toBe(false)
106
+ })
107
+
108
+ test('should return false for one object being null', () => {
109
+ const objA = { a: 1, b: 'hello' }
110
+ const objB = null
111
+ expect(shallow(objA, objB)).toBe(false)
112
+ })
113
+
114
+ test('should return false for one object being undefined', () => {
115
+ const objA = { a: 1, b: 'hello' }
116
+ const objB = undefined
117
+ expect(shallow(objA, objB)).toBe(false)
118
+ })
119
+
120
+ test('should return true for two null objects', () => {
121
+ const objA = null
122
+ const objB = null
123
+ expect(shallow(objA, objB)).toBe(true)
124
+ })
125
+
126
+ test('should return false for objects with different types', () => {
127
+ const objA = { a: 1, b: 'hello' }
128
+ const objB = { a: '1', b: 'hello' }
129
+ // @ts-ignore
130
+ expect(shallow(objA, objB)).toBe(false)
131
+ })
132
+ })