-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
62de727
commit fc95fc8
Showing
3 changed files
with
55 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters