Skip to content

Commit

Permalink
immer test
Browse files Browse the repository at this point in the history
  • Loading branch information
Ruben-Arushanyan committed Oct 3, 2023
1 parent 130c91c commit a822d5e
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions test/Store/Store.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,52 @@ test('Store | updateState', () => {
expect(store.state).toEqual({a: 1, b: 2})
})

// updateStateImmer
test('Store | updateStateImmer', () => {
const s1 = {
a: {
b: 2,
c: 3,
},
d: {
e: 100,
f: 200,
}
}
const store = new Store(s1)
store.updateState((state) => {
state.a.b = 22
})
expect(store.state).toEqual({
a: {
b: 22,
c: 3,
},
d: {
e: 100,
f: 200,
}
})
expect(store.state.d).toBe(s1.d)


const s2 = {a: 1, b: 2}
store.updateState((state) => {
return s2
})

expect(store.state).toEqual(s2)
expect(store.state).toBe(s2)

store.updateState((state) => {
state.a = 1
state.b = 2
})

expect(store.state).toEqual(s2)
expect(store.state).toBe(s2)
})

// subscribe
test('Store | subscribe', () => {
const stack = []
Expand Down

0 comments on commit a822d5e

Please sign in to comment.