diff options
author | Hsuan Lee <hsuan@cobinhood.com> | 2019-01-19 18:42:04 +0800 |
---|---|---|
committer | Hsuan Lee <hsuan@cobinhood.com> | 2019-01-19 18:42:04 +0800 |
commit | 7ae38906926dc09bc10670c361af0d2bf0050426 (patch) | |
tree | 5fb10ae366b987db09e4ddb4bc3ba0f75404ad08 /packages/dev-utils/src/callback_error_reporter.ts | |
parent | b5fd3c72a08aaa6957917d74c333387a16edf66b (diff) | |
download | dexon-sol-tools-7ae38906926dc09bc10670c361af0d2bf0050426.tar.gz dexon-sol-tools-7ae38906926dc09bc10670c361af0d2bf0050426.tar.zst dexon-sol-tools-7ae38906926dc09bc10670c361af0d2bf0050426.zip |
Update dependency packages
Diffstat (limited to 'packages/dev-utils/src/callback_error_reporter.ts')
-rw-r--r-- | packages/dev-utils/src/callback_error_reporter.ts | 77 |
1 files changed, 0 insertions, 77 deletions
diff --git a/packages/dev-utils/src/callback_error_reporter.ts b/packages/dev-utils/src/callback_error_reporter.ts deleted file mode 100644 index b993bf22a..000000000 --- a/packages/dev-utils/src/callback_error_reporter.ts +++ /dev/null @@ -1,77 +0,0 @@ -import * as chai from 'chai'; -import * as _ from 'lodash'; - -import { DoneCallback } from '@0x/types'; - -const expect = chai.expect; - -export const callbackErrorReporter = { - reportNoErrorCallbackErrors( - done: DoneCallback, - expectToBeCalledOnce: boolean = true, - ): <T>(f?: ((value: T) => void) | undefined) => (value: T) => void { - const callback = <T>(f?: (value: T) => void) => { - const wrapped = (value: T) => { - if (_.isUndefined(f)) { - done(); - return; - } - try { - f(value); - if (expectToBeCalledOnce) { - done(); - } - } catch (err) { - done(err); - } - }; - return wrapped; - }; - return callback; - }, - reportNodeCallbackErrors( - done: DoneCallback, - expectToBeCalledOnce: boolean = true, - ): <T>(f?: ((value: T) => void) | undefined) => (error: Error | null, value: T | undefined) => void { - const callback = <T>(f?: (value: T) => void) => { - const wrapped = (error: Error | null, value: T | undefined) => { - if (!_.isNull(error)) { - done(error); - } else { - if (_.isUndefined(f)) { - done(); - return; - } - try { - f(value as T); - if (expectToBeCalledOnce) { - done(); - } - } catch (err) { - done(err); - } - } - }; - return wrapped; - }; - return callback; - }, - assertNodeCallbackError( - done: DoneCallback, - errMsg: string, - ): <T>(error: Error | null, value: T | undefined) => void { - const wrapped = <T>(error: Error | null, _value: T | undefined) => { - if (_.isNull(error)) { - done(new Error('Expected callback to receive an error')); - } else { - try { - expect(error.message).to.be.equal(errMsg); - done(); - } catch (err) { - done(err); - } - } - }; - return wrapped; - }, -}; |