@tanstack/vue-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 +1 -1
- package/src/__tests__/index.test.tsx +54 -1
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@ import { h, defineComponent, watch } from 'vue-demi'
|
|
|
2
2
|
import { render, waitFor } from '@testing-library/vue'
|
|
3
3
|
import '@testing-library/jest-dom'
|
|
4
4
|
import { Store } from '@tanstack/store'
|
|
5
|
-
import { useStore } from '../index'
|
|
5
|
+
import { useStore, shallow } from '../index'
|
|
6
6
|
import userEvent from '@testing-library/user-event'
|
|
7
7
|
|
|
8
8
|
const user = userEvent.setup()
|
|
@@ -79,3 +79,56 @@ describe('useStore', () => {
|
|
|
79
79
|
expect(getByText('Number rendered: 2')).toBeInTheDocument()
|
|
80
80
|
})
|
|
81
81
|
})
|
|
82
|
+
|
|
83
|
+
describe('shallow', () => {
|
|
84
|
+
test('should return true for shallowly equal objects', () => {
|
|
85
|
+
const objA = { a: 1, b: 'hello' }
|
|
86
|
+
const objB = { a: 1, b: 'hello' }
|
|
87
|
+
expect(shallow(objA, objB)).toBe(true)
|
|
88
|
+
})
|
|
89
|
+
|
|
90
|
+
test('should return false for objects with different values', () => {
|
|
91
|
+
const objA = { a: 1, b: 'hello' }
|
|
92
|
+
const objB = { a: 2, b: 'world' }
|
|
93
|
+
expect(shallow(objA, objB)).toBe(false)
|
|
94
|
+
})
|
|
95
|
+
|
|
96
|
+
test('should return false for objects with different keys', () => {
|
|
97
|
+
const objA = { a: 1, b: 'hello' }
|
|
98
|
+
const objB = { a: 1, c: 'world' }
|
|
99
|
+
// @ts-ignore
|
|
100
|
+
expect(shallow(objA, objB)).toBe(false)
|
|
101
|
+
})
|
|
102
|
+
|
|
103
|
+
test('should return false for objects with different structures', () => {
|
|
104
|
+
const objA = { a: 1, b: 'hello' }
|
|
105
|
+
const objB = [1, 'hello']
|
|
106
|
+
// @ts-ignore
|
|
107
|
+
expect(shallow(objA, objB)).toBe(false)
|
|
108
|
+
})
|
|
109
|
+
|
|
110
|
+
test('should return false for one object being null', () => {
|
|
111
|
+
const objA = { a: 1, b: 'hello' }
|
|
112
|
+
const objB = null
|
|
113
|
+
expect(shallow(objA, objB)).toBe(false)
|
|
114
|
+
})
|
|
115
|
+
|
|
116
|
+
test('should return false for one object being undefined', () => {
|
|
117
|
+
const objA = { a: 1, b: 'hello' }
|
|
118
|
+
const objB = undefined
|
|
119
|
+
expect(shallow(objA, objB)).toBe(false)
|
|
120
|
+
})
|
|
121
|
+
|
|
122
|
+
test('should return true for two null objects', () => {
|
|
123
|
+
const objA = null
|
|
124
|
+
const objB = null
|
|
125
|
+
expect(shallow(objA, objB)).toBe(true)
|
|
126
|
+
})
|
|
127
|
+
|
|
128
|
+
test('should return false for objects with different types', () => {
|
|
129
|
+
const objA = { a: 1, b: 'hello' }
|
|
130
|
+
const objB = { a: '1', b: 'hello' }
|
|
131
|
+
// @ts-ignore
|
|
132
|
+
expect(shallow(objA, objB)).toBe(false)
|
|
133
|
+
})
|
|
134
|
+
})
|