« get me outta code hell

hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/test/lib/strict-match-error.js
diff options
context:
space:
mode:
Diffstat (limited to 'test/lib/strict-match-error.js')
-rw-r--r--test/lib/strict-match-error.js50
1 files changed, 0 insertions, 50 deletions
diff --git a/test/lib/strict-match-error.js b/test/lib/strict-match-error.js
deleted file mode 100644
index e3b36e93..00000000
--- a/test/lib/strict-match-error.js
+++ /dev/null
@@ -1,50 +0,0 @@
-export function strictlyThrows(t, fn, pattern) {
-  const error = catchErrorOrNull(fn);
-
-  t.currentAssert = strictlyThrows;
-
-  if (error === null) {
-    t.fail(`expected to throw`);
-    return;
-  }
-
-  const nameAndMessage = `${pattern.constructor.name} ${pattern.message}`;
-  t.match(
-    prepareErrorForMatch(error),
-    prepareErrorForMatch(pattern),
-    (pattern instanceof AggregateError
-      ? `expected to throw: ${nameAndMessage} (${pattern.errors.length} error(s))`
-      : `expected to throw: ${nameAndMessage}`));
-}
-
-function prepareErrorForMatch(error) {
-  if (error instanceof RegExp) {
-    return {
-      message: error,
-    };
-  }
-
-  if (!(error instanceof Error)) {
-    return error;
-  }
-
-  const matchable = {
-    name: error.constructor.name,
-    message: error.message,
-  };
-
-  if (error instanceof AggregateError) {
-    matchable.errors = error.errors.map(prepareErrorForMatch);
-  }
-
-  return matchable;
-}
-
-function catchErrorOrNull(fn) {
-  try {
-    fn();
-    return null;
-  } catch (error) {
-    return error;
-  }
-}