How to use the alsatian.TestCase function in alsatian

To help you get started, we’ve selected a few alsatian examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github TypeScriptToLua / TypeScriptToLua / test / unit / cli.spec.ts View on Github external
import { Expect, Test, TestCase } from "alsatian";

import { findConfigFile, parseCommandLine } from "../../src/CommandLineParser";

export class CLITests {

    @Test("defaultOption")
    @TestCase("luaTarget", "JIT")
    @TestCase("noHeader", false)
    @TestCase("luaLibImport", "inline")
    @TestCase("rootDir", process.cwd())
    @TestCase("outDir", process.cwd())
    public defaultOptions(option: any, expected: any): void {
        const parsedCommandLine = parseCommandLine([]);

        Expect(expected).toBe(parsedCommandLine.options[option]);
    }

    @Test("ValidLuaTarget")
    public validLuaTarget(): void {
        const parsedCommandLine = parseCommandLine(['--luaTarget', '5.3']);
        Expect(parsedCommandLine.options["luaTarget"]).toBe("5.3");
    }

    @Test("InvalidLuaTarget")
    public invalidLuaTarget(): void {
        // Don't check error message because the yargs library messes the message up.
        Expect(() => parseCommandLine(['--luaTarget', '42'])).toThrow();
github TypeScriptToLua / TypeScriptToLua / test / unit / cli.spec.ts View on Github external
import { Expect, Test, TestCase } from "alsatian";

import { findConfigFile, parseCommandLine } from "../../src/CommandLineParser";

export class CLITests {

    @Test("defaultOption")
    @TestCase("luaTarget", "JIT")
    @TestCase("noHeader", false)
    @TestCase("luaLibImport", "inline")
    @TestCase("rootDir", process.cwd())
    @TestCase("outDir", process.cwd())
    public defaultOptions(option: any, expected: any): void {
        const parsedCommandLine = parseCommandLine([]);

        Expect(expected).toBe(parsedCommandLine.options[option]);
    }

    @Test("ValidLuaTarget")
    public validLuaTarget(): void {
        const parsedCommandLine = parseCommandLine(['--luaTarget', '5.3']);
        Expect(parsedCommandLine.options["luaTarget"]).toBe("5.3");
    }

    @Test("InvalidLuaTarget")
    public invalidLuaTarget(): void {
        // Don't check error message because the yargs library messes the message up.
github 01alchemist / TurboScript / debug / turboscript.spec__.ts View on Github external
* Called once after every test
     */
    @Teardown
    public teardown() {
        debug("teardown:+");

        // Add code

        debug("teardown:-");
    }

    /**
     * An example synchronous test which adds two numbers using TypeScript
     */
    @TestCase(1, 2, 3)
    @TestCase(-1, 2, 1)
    @TestCase(0, 0, 0)
    @Test("Test adding two numbers using TypeScript")
    public testAddTwoTypeScript(val1: number, val2: number, expectedResult: number) {
        debug("testAddTwoTypeScript:+");

        Expect(val1 + val2).toBe(expectedResult);

        debug("testAddTwoTypeScript:-");
    }

    /**
     * Test TurboScript can add numbers
     */
    @TestCase(1, 2, 3)
    @TestCase(-1, 2, 1)
    @TestCase(0, 0, 0)
github alsatian-test / alsatian / test / integration-tests / test-sets / test-syntax / case-arguments.spec.ts View on Github external
import { Expect, TestCase, TestFixture } from "alsatian";

export class CaseArgumentTestsTests {
   @TestCase(1, 2, 3)
   @TestCase(1.5, 2.5, 4)
   public AddNumbers(first: number, second: number, expected: number) {
      Expect(first + second).toBe(expected);
   }

   @TestCase("Hello", " world!", "Hello world!")
   @TestCase("Far", "away", "Faraway")
   public AddStrings(first: number, second: number, expected: number) {
      Expect(first + second).toBe(expected);
   }

   @TestCase({a: 1}, {a: 2}, 3)
   public AddObjectProperty(first: {a: number}, second: {a: number}, expected: number) {
      Expect(first.a + second.a).toBe(expected);
   }

   @TestCase([1, 2], [3, 4], 10)
   public AddArray(first: Array, second: Array, expected: number) {
      const reduced = [...first, ...second].reduce((agg, curr) => agg + curr, 0);
      Expect(reduced).toBe(expected);
   }
}
github alsatian-test / alsatian / test / integration-tests / test-sets / test-syntax / case-arguments.spec.ts View on Github external
import { Expect, TestCase, TestFixture } from "alsatian";

export class CaseArgumentTestsTests {
   @TestCase(1, 2, 3)
   @TestCase(1.5, 2.5, 4)
   public AddNumbers(first: number, second: number, expected: number) {
      Expect(first + second).toBe(expected);
   }

   @TestCase("Hello", " world!", "Hello world!")
   @TestCase("Far", "away", "Faraway")
   public AddStrings(first: number, second: number, expected: number) {
      Expect(first + second).toBe(expected);
   }

   @TestCase({a: 1}, {a: 2}, 3)
   public AddObjectProperty(first: {a: number}, second: {a: number}, expected: number) {
      Expect(first.a + second.a).toBe(expected);
   }

   @TestCase([1, 2], [3, 4], 10)

alsatian

TypeScript and JavaScript testing framework for beautiful and readable tests

MIT
Latest version published 5 years ago

Package Health Score

47 / 100
Full package analysis