Skip to content

Commit

Permalink
npmignore
Browse files Browse the repository at this point in the history
  • Loading branch information
taichunmin committed May 6, 2024
1 parent c311715 commit 6938c4e
Show file tree
Hide file tree
Showing 3 changed files with 196 additions and 13 deletions.
2 changes: 2 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -137,5 +137,7 @@ out
/*.config.js
/dist/assets
/tsconfig.json
/tsdoc.json
/tsup.config.ts
/typedoc
/typedoc.json
16 changes: 14 additions & 2 deletions lib/buffer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1638,8 +1638,10 @@ describe('Buffer.unpack()', () => {
describe('Buffer.iterUnpack()', () => {
test('should unpack all tuples', () => {
const buf1 = Buffer.from('01fe01fe', 'hex')
const actual = [...buf1.iterUnpack('!BB')]
expect(actual).toEqual([[1, 254], [1, 254]])
const actual1 = [...buf1.iterUnpack('!BB')]
expect(actual1).toEqual([[1, 254], [1, 254]])
const actual2 = [...Buffer.iterUnpack(buf1, '!BB')]
expect(actual2).toEqual([[1, 254], [1, 254]])
})

test('should throw error with invalid type of buf', () => {
Expand All @@ -1661,6 +1663,16 @@ describe('Buffer.iterUnpack()', () => {
expect(err.message).toMatch(/lenRequired/)
}
})

test('should throw error with unknown format', () => {
expect.hasAssertions()
try {
jest.spyOn(Buffer, 'packParseFormat').mockReturnValueOnce({ littleEndian: false, items: [[1, 'z']] })
console.log([...Buffer.iterUnpack(Buffer.from('00', 'hex'), 'z')])
} catch (err) {
expect(err.message).toMatch(/Unknown format/)
}
})
})

describe('Buffer.packParseFormat()', () => {
Expand Down
Loading

0 comments on commit 6938c4e

Please sign in to comment.