testdeck-mocha

Mocha testing with style - the OOP way
import { suite, test } from "testdeck-mocha";
@suite
class Hello {
@test
world() {
}
}
Documentation Licensing
All documentation is licenced under the CC BY-NC 4.0 license.
You need legal consent by all direct maintainers of the project in order to use (parts of) the documentation for any
commercial purposes.
Features
- Object Oriented Interface
- Parameterised Tests
- Dependency Injection Support
- Watcher
Installation
Just run
npm install --save-dev testdeck-mocha
npm install --save-dev @types/mocha
and you are ready to go.
You might also want to consider using the very good Chai BDD/TDD assertion framework.
npm install --save-dev chai
npm install --save-dev @types/chai
And, depending on your project, you will also have to install the type declarations for node.
npm install --save-dev @types/node
Usage
Classes can be annotated with @suite
to make them test suites, similarly so, individual methods of test suites can
be annotated using @test
. And, by using inheritance, one can build complex test suites and reuse existing
code.
The test interface also supports mocha's built-in BDD and TDD interfaces such as describe
and it
.
And you can mix both the OOP style and the declarative style, and you can even create nested suites by using a mixture
of both styles.
import { assert } from "chai";
import { suite, test, describe, it } from "testdeck-mocha";
@suite
class Suite {
@test
method() {}
}
describe("outer", () => {
it("one", () => {});
@suite
class Inner {
@test
method() {}
}
});
abstract class TestBase {
@test
commonTest() {
}
}
@suite
class ConcreteTest extends TestBase {
@test
specificTest() {
}
}
Please keep in mind, that when the tests are run, a new instance of the test suite will be instantiated before each test
method is executed.
Watcher
testdeck-mocha comes with a watcher script that runs the TypeScript compiler in watch mode. So whenever your code
changes and compiles, your tests will be run, too.
Further Reading
Contributors
