Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ts-mocha

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ts-mocha

Mocha thin wrapper that allows running TypeScript tests with TypeScript runtime (ts-node) to get rid of compilation complexity

  • 9.0.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
470K
decreased by-4.66%
Maintainers
1
Weekly downloads
 
Created

What is ts-mocha?

The ts-mocha package is a TypeScript test runner for Mocha, allowing you to write and run Mocha tests in TypeScript without needing to compile your TypeScript files beforehand. It simplifies the process of testing TypeScript code by integrating directly with Mocha.

What are ts-mocha's main functionalities?

Running TypeScript Tests

This feature allows you to run Mocha tests written in TypeScript directly. The code sample demonstrates a simple test case using Mocha's `describe` and `it` functions to test an array's `indexOf` method.

const assert = require('assert');

describe('Array', function() {
  describe('#indexOf()', function() {
    it('should return -1 when the value is not present', function() {
      assert.strictEqual([1, 2, 3].indexOf(4), -1);
    });
  });
});

Integration with TypeScript

This feature highlights the ability to use TypeScript-specific features such as type annotations within your tests. The code sample shows a test case using Chai's `expect` assertion library to validate a TypeScript variable.

import { expect } from 'chai';

describe('TypeScript Test', () => {
  it('should support TypeScript features', () => {
    const result: number = 5;
    expect(result).to.equal(5);
  });
});

Configuration via tsconfig.json

This feature allows you to configure TypeScript compilation settings using a `tsconfig.json` file. The code sample shows a basic `tsconfig.json` configuration that specifies compiler options and includes/excludes certain files.

{
  "compilerOptions": {
    "module": "commonjs",
    "target": "es6",
    "outDir": "./dist",
    "rootDir": "./src",
    "strict": true
  },
  "include": ["src/**/*.ts"],
  "exclude": ["node_modules"]
}

Other packages similar to ts-mocha

Keywords

FAQs

Package last updated on 12 Jan 2022

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