Skip to content
This repository has been 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

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

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);
  });
}