aboutsummaryrefslogtreecommitdiffstats
path: root/packages/0x.js/test/utils
diff options
context:
space:
mode:
authorLeonid Logvinov <logvinov.leon@gmail.com>2018-01-05 22:33:00 +0800
committerLeonid Logvinov <logvinov.leon@gmail.com>2018-01-10 18:24:37 +0800
commitc8c86c44f8b978d74e03c11d4bb1813e76574af3 (patch)
tree3caa7b2613496052ca90176822ace79fc28dcc44 /packages/0x.js/test/utils
parentf917a4a34a9d7b25de85f9ce5adafa0f16ea6618 (diff)
downloaddexon-sol-tools-c8c86c44f8b978d74e03c11d4bb1813e76574af3.tar
dexon-sol-tools-c8c86c44f8b978d74e03c11d4bb1813e76574af3.tar.gz
dexon-sol-tools-c8c86c44f8b978d74e03c11d4bb1813e76574af3.tar.bz2
dexon-sol-tools-c8c86c44f8b978d74e03c11d4bb1813e76574af3.tar.lz
dexon-sol-tools-c8c86c44f8b978d74e03c11d4bb1813e76574af3.tar.xz
dexon-sol-tools-c8c86c44f8b978d74e03c11d4bb1813e76574af3.tar.zst
dexon-sol-tools-c8c86c44f8b978d74e03c11d4bb1813e76574af3.zip
Fix callback types
Diffstat (limited to 'packages/0x.js/test/utils')
-rw-r--r--packages/0x.js/test/utils/report_callback_errors.ts60
1 files changed, 55 insertions, 5 deletions
diff --git a/packages/0x.js/test/utils/report_callback_errors.ts b/packages/0x.js/test/utils/report_callback_errors.ts
index 8a8f4d966..7890e7cd3 100644
--- a/packages/0x.js/test/utils/report_callback_errors.ts
+++ b/packages/0x.js/test/utils/report_callback_errors.ts
@@ -1,10 +1,22 @@
-import { DoneCallback } from '../../src/types';
+import * as chai from 'chai';
+import * as _ from 'lodash';
-export const reportCallbackErrors = (done: DoneCallback) => {
- return (f: (...args: any[]) => void) => {
- const wrapped = async (...args: any[]) => {
+import { DoneCallback, OrderState } from '../../src/types';
+
+const expect = chai.expect;
+
+export const reportNoErrorCallbackErrors = (done: DoneCallback, expectToBeCalledOnce = true) => {
+ return <T>(f?: (value: T) => void) => {
+ const wrapped = (value: T) => {
+ if (_.isUndefined(f)) {
+ done();
+ return;
+ }
try {
- f(...args);
+ f(value);
+ if (expectToBeCalledOnce) {
+ done();
+ }
} catch (err) {
done(err);
}
@@ -12,3 +24,41 @@ export const reportCallbackErrors = (done: DoneCallback) => {
return wrapped;
};
};
+
+export const reportNodeCallbackErrors = (done: DoneCallback) => {
+ return <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);
+ done();
+ } catch (err) {
+ done(err);
+ }
+ }
+ };
+ return wrapped;
+ };
+};
+
+export const assertNodeCallbackError = (done: DoneCallback, errMsg: string) => {
+ 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;
+};