@@ -2,99 +2,8 @@ import { useState } from 'react'
22import { act , fireEvent , render } from '@testing-library/react'
33import { beforeEach , describe , expect , it , vi } from 'vitest'
44import { create } from 'zustand'
5- import { shallow , useShallow } from 'zustand/shallow'
6-
7- describe ( 'shallow' , ( ) => {
8- it ( 'compares primitive values' , ( ) => {
9- expect ( shallow ( true , true ) ) . toBe ( true )
10- expect ( shallow ( true , false ) ) . toBe ( false )
11-
12- expect ( shallow ( 1 , 1 ) ) . toBe ( true )
13- expect ( shallow ( 1 , 2 ) ) . toBe ( false )
14-
15- expect ( shallow ( 'zustand' , 'zustand' ) ) . toBe ( true )
16- expect ( shallow ( 'zustand' , 'redux' ) ) . toBe ( false )
17- } )
18-
19- it ( 'compares objects' , ( ) => {
20- expect ( shallow ( { foo : 'bar' , asd : 123 } , { foo : 'bar' , asd : 123 } ) ) . toBe (
21- true
22- )
23-
24- expect (
25- shallow ( { foo : 'bar' , asd : 123 } , { foo : 'bar' , foobar : true } )
26- ) . toBe ( false )
27-
28- expect (
29- shallow ( { foo : 'bar' , asd : 123 } , { foo : 'bar' , asd : 123 , foobar : true } )
30- ) . toBe ( false )
31- } )
32-
33- it ( 'compares arrays' , ( ) => {
34- expect ( shallow ( [ 1 , 2 , 3 ] , [ 1 , 2 , 3 ] ) ) . toBe ( true )
35-
36- expect ( shallow ( [ 1 , 2 , 3 ] , [ 2 , 3 , 4 ] ) ) . toBe ( false )
37-
38- expect (
39- shallow ( [ { foo : 'bar' } , { asd : 123 } ] , [ { foo : 'bar' } , { asd : 123 } ] )
40- ) . toBe ( false )
41-
42- expect ( shallow ( [ { foo : 'bar' } ] , [ { foo : 'bar' , asd : 123 } ] ) ) . toBe ( false )
43- } )
44-
45- it ( 'compares Maps' , ( ) => {
46- function createMap < T extends object > ( obj : T ) {
47- return new Map ( Object . entries ( obj ) )
48- }
49-
50- expect (
51- shallow (
52- createMap ( { foo : 'bar' , asd : 123 } ) ,
53- createMap ( { foo : 'bar' , asd : 123 } )
54- )
55- ) . toBe ( true )
56-
57- expect (
58- shallow (
59- createMap ( { foo : 'bar' , asd : 123 } ) ,
60- createMap ( { foo : 'bar' , foobar : true } )
61- )
62- ) . toBe ( false )
63-
64- expect (
65- shallow (
66- createMap ( { foo : 'bar' , asd : 123 } ) ,
67- createMap ( { foo : 'bar' , asd : 123 , foobar : true } )
68- )
69- ) . toBe ( false )
70- } )
71-
72- it ( 'compares Sets' , ( ) => {
73- expect ( shallow ( new Set ( [ 'bar' , 123 ] ) , new Set ( [ 'bar' , 123 ] ) ) ) . toBe ( true )
74-
75- expect ( shallow ( new Set ( [ 'bar' , 123 ] ) , new Set ( [ 'bar' , 2 ] ) ) ) . toBe ( false )
76-
77- expect ( shallow ( new Set ( [ 'bar' , 123 ] ) , new Set ( [ 'bar' , 123 , true ] ) ) ) . toBe (
78- false
79- )
80- } )
81-
82- it ( 'compares functions' , ( ) => {
83- function firstFnCompare ( ) {
84- return { foo : 'bar' }
85- }
86-
87- function secondFnCompare ( ) {
88- return { foo : 'bar' }
89- }
90-
91- expect ( shallow ( firstFnCompare , firstFnCompare ) ) . toBe ( true )
92-
93- expect ( shallow ( secondFnCompare , secondFnCompare ) ) . toBe ( true )
94-
95- expect ( shallow ( firstFnCompare , secondFnCompare ) ) . toBe ( false )
96- } )
97- } )
5+ import { useShallow } from 'zustand/react/shallow'
6+ import { shallow } from 'zustand/vanilla/shallow'
987
998describe ( 'types' , ( ) => {
1009 it ( 'works with useBoundStore and array selector (#1107)' , ( ) => {
@@ -123,17 +32,6 @@ describe('types', () => {
12332 } )
12433} )
12534
126- describe ( 'unsupported cases' , ( ) => {
127- it ( 'date' , ( ) => {
128- expect (
129- shallow (
130- new Date ( '2022-07-19T00:00:00.000Z' ) ,
131- new Date ( '2022-07-20T00:00:00.000Z' )
132- )
133- ) . not . toBe ( false )
134- } )
135- } )
136-
13735describe ( 'useShallow' , ( ) => {
13836 const testUseShallowSimpleCallback =
13937 vi . fn < [ { selectorOutput : string [ ] ; useShallowOutput : string [ ] } ] > ( )
0 commit comments