Skip to content

Commit

Permalink
chore: basic wrap tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Cherry committed Sep 14, 2024
1 parent 8838315 commit f701c6c
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"recommendations": ["EditorConfig.EditorConfig", "esbenp.prettier-vscode"]
}
4 changes: 4 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"editor.formatOnSave": true,
"editor.defaultFormatter": "esbenp.prettier-vscode"
}
39 changes: 39 additions & 0 deletions test/wrap.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { describe, it, expect } from 'vitest'

import { isWrapped, isProxyable, wrap, unwrap, passthroughGet } from '../src/wrap'

describe('wrap', () => {
it('isWrapped', () => {
const unwrapped = { foo: 'bar' }
const wrapped = wrap(unwrapped, {})
expect(isWrapped(unwrapped)).toBe(false)
expect(isWrapped(wrapped)).toBe(true)
})

it('isProxyable', () => {
expect(isProxyable(null)).toBe(false)
expect(isProxyable({})).toBe(true)
expect(isProxyable(() => {})).toBe(true)
})

it('wrap', () => {
const unwrapped = { foo: 'bar', baz: 'qux' }
const wrapped = wrap(unwrapped, {
get(target, prop) {
if (prop === 'foo') {
return 'baz'
}
return passthroughGet(target, prop)
},
})
expect(wrapped.foo).toBe('baz')
expect(wrapped.baz).toBe('qux')
expect(unwrap(wrapped)).toBe(unwrapped)
})

it('unwrap', () => {
const unwrapped = { foo: 'bar' }
const wrapped = wrap(unwrapped, {})
expect(unwrap(wrapped)).toBe(unwrapped)
})
})

0 comments on commit f701c6c

Please sign in to comment.