New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@testdeck/mocha

Package Overview
Dependencies
Maintainers
2
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@testdeck/mocha

TypeScript decorators based wrapper over mocha's interface

  • 0.0.4
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
15K
increased by10.55%
Maintainers
2
Weekly downloads
 
Created
Source

testdeck-mocha

Get it on NPM Downloads per Week Dependencies Issues Pull Requests Travis Build Status Appveyor Build Status Apache 2.0 License

Mocha testing with style - the OOP way

import { suite, test } from "testdeck-mocha";

@suite
class Hello {
  
    @test
    world() {
      // place your assertions here
    }
}

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() {}
}

// mixed operations
describe("outer", () => {
    it("one", () => {});
    
    @suite
    class Inner {
      
        @test
        method() {}
    }
});

// abstract suites
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

FAQs

Package last updated on 05 Apr 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc