Skip to content

Instantly share code, notes, and snippets.

@anupam-io
Last active April 4, 2021 16:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anupam-io/ecf8f0caa1897dd88cff747be02b7885 to your computer and use it in GitHub Desktop.
Save anupam-io/ecf8f0caa1897dd88cff747be02b7885 to your computer and use it in GitHub Desktop.
Mimicking `mocha`'s it utitlity.
const assert = require("assert");
async function it(name, fun) {
await fun()
.then(() => {
console.log(name, ": passed.");
})
.catch((err) => {
console.log(name, ": failed.");
console.log("Error: ", err);
});
}
it("MyTest", async () => {
assert(true);
});
it("MyTest", async () => {
assert(false);
});
@anupam-io
Copy link
Author

Output:

MyTest : passed.
MyTest : failed.
Error:  { AssertionError [ERR_ASSERTION]: The expression evaluated to a falsy value:

  assert(false)

    at it (/home/pam/ERC1155-holder-distributor/main.js:18:3)
    at it (/home/pam/ERC1155-holder-distributor/main.js:4:9)
    at Object.<anonymous> (/home/pam/ERC1155-holder-distributor/main.js:17:1)
    at Module._compile (internal/modules/cjs/loader.js:778:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
    at Module.load (internal/modules/cjs/loader.js:653:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
    at Function.Module._load (internal/modules/cjs/loader.js:585:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:831:12)
    at startup (internal/bootstrap/node.js:283:19)
  generatedMessage: true,
  name: 'AssertionError [ERR_ASSERTION]',
  code: 'ERR_ASSERTION',
  actual: false,
  expected: true,
  operator: '==' }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment