Skip to content

Commit

Permalink
test: add unit tests for "getPublicData"
Browse files Browse the repository at this point in the history
  • Loading branch information
kettanaito committed Mar 30, 2024
1 parent 77f4ad2 commit 3ed3d49
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions src/core/ws/utils/getPublicData.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { getPublicData } from './getPublicData'

it('returns a short string as-is', async () => {
expect(await getPublicData('')).toBe('')
expect(await getPublicData('hello')).toBe('hello')
})

it('returns a truncated long string', async () => {
expect(await getPublicData('this is a very long string')).toBe(
'this is a very long stri…',
)
})

it('returns a short Blob text as-is', async () => {
expect(await getPublicData(new Blob(['']))).toBe('Blob()')
expect(await getPublicData(new Blob(['hello']))).toBe('Blob(hello)')
})

it('returns a truncated long Blob text', async () => {
expect(await getPublicData(new Blob(['this is a very long string']))).toBe(
'Blob(this is a very long stri…)',
)
})

it('returns a short ArrayBuffer text as-is', async () => {
expect(await getPublicData(new TextEncoder().encode(''))).toBe(
'ArrayBuffer()',
)
expect(await getPublicData(new TextEncoder().encode('hello'))).toBe(
'ArrayBuffer(hello)',
)
})

it('returns a truncated ArrayBuffer text', async () => {
expect(
await getPublicData(new TextEncoder().encode('this is a very long string')),
).toBe('ArrayBuffer(this is a very long stri…)')
})

0 comments on commit 3ed3d49

Please sign in to comment.