Skip to content
This repository was archived by the owner on Jan 2, 2024. It is now read-only.

A mocha boilerplate that allows to dynamically define tests

License

Notifications You must be signed in to change notification settings

gurisko/dynamic-mocha-typescript

Folders and files

NameName
Last commit message
Last commit date

Latest commit

b910ebf · Nov 17, 2020

History

11 Commits
Apr 5, 2019
Apr 5, 2019
Apr 4, 2019
Sep 3, 2019
Nov 17, 2020
Mar 23, 2020
Apr 5, 2019
Apr 5, 2019

Repository files navigation

dynamic-mocha-typescript

This repository is an example of how to reuse Mocha test-cases and follow DRY principles. It proved to be especially useful in end-to-end web testing where authentication/authorisation workflow has to be often repeated.

Example

function anotherTest(message: string) {
  return it(message, () => true);
}

export function exampleTest() {
  describe('Example Test', function() {
    before(() => {
      this.unshiftTests([
        anotherTest('should be 2nd'),
        anotherTest('should be 3rd'),
      ]);
      this.unshiftTest(anotherTest('should be 1st'));
      this.pushTest(anotherTest('should be 5th'));
      this.pushTests([
        anotherTest('should be 6th'),
        anotherTest('should be 7th'),
      ]);
    });

    it('should be 4th (static)', () => true);
  });
}