Skip to content

Commit ef2ca9d

Browse files
committed
cover new method
1 parent 65c5c30 commit ef2ca9d

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

src/primitives/__tests/utils.test.ts

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ import {
77
fromBase58,
88
toBase58,
99
fromBase58Check,
10-
toBase58Check
10+
toBase58Check,
11+
verifyNotNull
1112
} from '../../primitives/utils'
1213

1314
describe('utils', () => {
@@ -207,3 +208,28 @@ describe('utils', () => {
207208
expect(toArray(input)).toEqual(expected)
208209
})
209210
})
211+
212+
describe('verifyNotNull', () => {
213+
it('should return the value if it is not null or undefined', () => {
214+
expect(verifyNotNull(42)).toBe(42)
215+
expect(verifyNotNull('hello')).toBe('hello')
216+
expect(verifyNotNull({})).toEqual({})
217+
expect(verifyNotNull([])).toEqual([])
218+
})
219+
220+
it('should throw an error with default message if value is null', () => {
221+
expect(() => verifyNotNull(null)).toThrow('Expected a valid value, but got undefined or null.')
222+
})
223+
224+
it('should throw an error with default message if value is undefined', () => {
225+
expect(() => verifyNotNull(undefined)).toThrow('Expected a valid value, but got undefined or null.')
226+
})
227+
228+
it('should throw an error with custom message if value is null', () => {
229+
expect(() => verifyNotNull(null, 'Custom error')).toThrow('Custom error')
230+
})
231+
232+
it('should throw an error with custom message if value is undefined', () => {
233+
expect(() => verifyNotNull(undefined, 'Another custom error')).toThrow('Another custom error')
234+
})
235+
})

0 commit comments

Comments
 (0)