TypeScript Unit Testing Alsatian

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Extensions
> Step 2: And Like the video. BONUS: You can also share it!

Example

Alsatian is a unit testing framework written in TypeScript. It allows for usage of Test Cases, and outputs TAP-compliant markup.

To use it, install it from npm:

npm install alsatian --save-dev

Then set up a test file:

import { Expect, Test, TestCase } from "alsatian";
import { SomeModule } from "../src/some-module";    

export SomeModuleTests {

    @Test()
    public statusShouldBeTrueByDefault() {
        let instance = new SomeModule();
        
        Expect(instance.status).toBe(true);
    }
    
    @Test("Name should be null by default")
    public nameShouldBeNullByDefault() {
        let instance = new SomeModule();
        
        Expect(instance.name).toBe(null);
    }
    
    @TestCase("first name")
    @TestCase("apples")
    public shouldSetNameCorrectly(name: string) {
        let instance = new SomeModule();
        
        instance.setName(name);
        
        Expect(instance.name).toBe(name);
    }
    
}

For a full documentation, see alsatian's GitHub repo.



Got any TypeScript Question?