node package manager

ts-test

ts-test

build status

A collection of utilities to test typescript node applications.

It is based on jasmine.

Installation

npm i -D ts-test

Setup

  • In your package.json file create a test script:

    {
      "scripts": {
        "test": "jasmine-ts 'path/to/specs/**/*.spec.ts further/specs/**/*.spec.ts specs/to/exclude/**/*.spec.ts'"
      }
    }
  • Initialize jasmine

    node_modules/.bin/jasmine-ts init

Run the tests

npm test

Utilities

async

The methods it(), beforeEach(), afterEach(), beforeAll() and afterAll() are wrapped by the async module. The callback you pass is executed within an async/await environment.

Example:

import {it} from "ts-test"
 
it("should work with promises", () =>
  new Promise(resolve => setTimeout(resolve, 100))
)

HttpClient

The HttpClient wraps the request module and creates promised requests. This is intended to be used for integration tests in combination with the async module.

Example:

import {HttpClient, await} from "ts-test";
let httpClient: HttpClient;
 
beforeAll(() => {
  httpClient = new HttpClient("localhost:12341");
});
 
it("should resolve if successful", () => {
  let response = await(httpClient.get("/resources"));
  expect(response.statusCode).toEqual(200);
  expect(response.body).toEqual([{id: 42, foo: "bar"}]);
});

For more examples you can have a look at the specs for the HttpClient.