Skip to content

Instantly share code, notes, and snippets.

@osartun
Last active May 7, 2025 06:46
Show Gist options
  • Select an option

  • Save osartun/d40a8f6d2b0b37bece376e974705beb6 to your computer and use it in GitHub Desktop.

Select an option

Save osartun/d40a8f6d2b0b37bece376e974705beb6 to your computer and use it in GitHub Desktop.

Revisions

  1. osartun revised this gist Jun 17, 2021. 1 changed file with 6 additions and 4 deletions.
    10 changes: 6 additions & 4 deletions coderPadTSTestUtils.ts
    Original file line number Diff line number Diff line change
    @@ -30,14 +30,16 @@ const it = (name: string, cb: Function) => {

    /* Happy coding: */

    const { expect } = require('chai')

    describe('My suite', () => {
    describe('My nested suite', () => {
    it('returns', () => {
    // Do some assertions here
    it('resolves successfully', () => {
    expect(true).to.equal(true);
    })

    it('throws', () => {
    throw new Error('Some problem occurred')
    it('throws an error', () => {
    expect(true).to.equal(false);
    })
    })
    })
  2. osartun created this gist Jun 17, 2021.
    43 changes: 43 additions & 0 deletions coderPadTSTestUtils.ts
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,43 @@
    /**
    * You want to use mocha in a TypeScript CoderPad but you get the error
    * message that `describe` isn't defined even though you're already using
    * the `mocha.suite.emit('pre-require', this, 'solution', mocha)` hack?
    *
    * > Cannot find name 'describe'. Do you need to install type definitions
    * > for a test runner? Try `npm i --save-dev @types/jest` or
    * > `npm i --save-dev @types/mocha`.
    *
    * Here are a couple of lines to copy & paste into your pad to use
    * `describe` and `it`:
    */

    const describe = (name: string, cb: Function) => {
    console.log(name);
    console.group();
    cb();
    console.groupEnd();
    }

    const it = (name: string, cb: Function) => {
    try {
    cb();
    console.log(`✅ ${name}`);
    } catch (e) {
    console.warn(`❌ ${name}`);
    console.error(e);
    }
    }

    /* Happy coding: */

    describe('My suite', () => {
    describe('My nested suite', () => {
    it('returns', () => {
    // Do some assertions here
    })

    it('throws', () => {
    throw new Error('Some problem occurred')
    })
    })
    })