Skip to content

Commit

Permalink
added snap test to proxySet
Browse files Browse the repository at this point in the history
  • Loading branch information
overthemike committed Oct 14, 2024
1 parent 37debaa commit e2b3f1e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/vanilla/utils/test.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { snapshot } from '../../vanilla.ts'
import { proxyMap } from './proxyMap-indexMap-keyval.ts'

Check warning on line 2 in src/vanilla/utils/test.ts

View workflow job for this annotation

GitHub Actions / lint

'proxyMap' is defined but never used. Allowed unused vars must match /^_/u
import { proxySet } from './proxySet.ts'

const state = proxyMap([['key1', 'val1']])
const state = proxySet(['val1', 'val2'])
const snap1 = snapshot(state)
console.log(snap1.has('key1'), 'true')
console.log(snap1.get('key1'), 'val1')
state.delete('key1')
console.log(snap1.has('val1'), 'true')
state.delete('val2')
const snap2 = snapshot(state)
console.log(snap1.has('key1'), 'true')
console.log(snap1.get('key1'), 'val1')
console.log(snap2.has('key1'), 'false')
console.log(snap2.get('key1'), 'undefined')
console.log(snap1.has('val1'), 'true')
console.log(snap1.has('val2'), 'true')
console.log(snap2.has('val1'), 'true')
console.log(snap2.has('val2'), 'false')
13 changes: 13 additions & 0 deletions tests/proxySet.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -351,4 +351,17 @@ describe('snapshot behavior', () => {
// @ts-expect-error - snapshot should not be able to mutate
expect(() => snap.clear()).toThrow('Cannot perform mutations on a snapshot')
})

it('should work with deleting a key', async () => {
const state = proxySet(['val1', 'val2'])
const snap1 = snapshot(state)
expect(snap1.has('val1')).toBe(true)
expect(snap1.has('val2')).toBe(true)
state.delete('val1')
const snap2 = snapshot(state)
expect(snap1.has('val1')).toBe(true)
expect(snap1.has('val2')).toBe(true)
expect(snap2.has('val1')).toBe(false)
expect(snap2.has('val2')).toBe(true)
})
})

0 comments on commit e2b3f1e

Please sign in to comment.