Skip to content

Commit

Permalink
add go test
Browse files Browse the repository at this point in the history
  • Loading branch information
napalmpapalam committed Oct 25, 2023
1 parent 62de727 commit fc95fc8
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 0 deletions.
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ module.exports = {
'@typescript-eslint/no-non-null-assertion': 0,
'simple-import-sort/imports': 'error',
'simple-import-sort/exports': 'error',
'prefer-const': ['error', { destructuring: 'all'}],
},
};

53 changes: 53 additions & 0 deletions packages/tools/src/go.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { go } from './go'

describe('preforms go unit test', () => {
describe('async callback should return', () => {
test('null result if error thrown', async () => {
const [err, result] = await go(async () => {
throw new Error('test error')
})

expect(err).toBeInstanceOf(Error)
expect(result).toBeNull()
})

test('result if no error thrown', async () => {
const [err, result] = await go(async () => {
return 'test result'
})
expect(err).toBeNull()
expect(result).toBe('test result')
})
})

describe('sync callback should return', () => {
test('null result if error thrown', async () => {
const [err, result] = await go(() => {
throw new Error('test error')
})
expect(err).toBeInstanceOf(Error)
expect(result).toBeNull()
})

test('result if no error thrown', async () => {
const [err, result] = await go(() => {
return 'test result'
})
expect(err).toBeNull()
expect(result).toBe('test result')
})
})

test('should redeclare error during few executions', async () => {
let [err, result] = await go(async () => {
throw new Error('test error')
})

expect(err).toBeInstanceOf(Error)
expect(result).toBeNull()
;[err] = await go(async () => {
return 'success'
})
expect(err).toBeNull()
})
})
1 change: 1 addition & 0 deletions packages/tools/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export * from '@/enums'
export * from '@/errors'
export * from '@/events'
export * from '@/go'
export * from '@/helpers'
export * from '@/math'
export * from '@/time'
Expand Down

0 comments on commit fc95fc8

Please sign in to comment.