Code Monkey home page Code Monkey logo

busted-tstl's Introduction

TypeScript declarations for Busted

This repository contains TypeScript declarations for Busted. An Elegant Lua unit testing framework.

You can install these via npm.

yarn add -D busted-tstl
# or
npm install -D busted-tstl

link them up in your tsconfig.json file.

It is recommended to use lua-types with these declarations as those will tell TypeScript about Lua's environment.

{
    "compilerOptions": {
        "lib": ["esnext"],
        "types": [
            "busted-tstl",
            "lua-types/5.1
        ]
    }
}

start creating your busted tests within .ts files (preferably with the suffix _spec.ts within a folder named spec).

describe("mocks", () => {
    it("replaces a table with spies", () => {
        const t = {
            thing: function (this: void, msg) { print(msg) }
        };

        const m = mock(t); // mocks the table with spies, so it will print

        m.thing("Coffee");
        assert.spy(m.thing).was.called_with("Coffee");
    });

    it("replaces a table with stubs", () => {
        const t = {
            thing: function (this: void, msg) { print(msg) }
        };

        const m = mock(t, true); // mocks the table with stubs, so it will not print

        m.thing("Coffee");
        assert.stub(m.thing).was.called_with("Coffee");
        mock.revert(m); // reverts all stubs/spies in m
        m.thing("Tea"); // DOES print 'Tea'
    });
});

Then transpile the file(s) with TypeScriptToLua and run busted!

tstl spec/test_spec.ts
tstl -p tsconfig.json
busted      # Install with `luarocks install busted`

It is recommended to use lua-types with these declarations as those will tell TypeScript about Lua's environment.

Assertion Statement Info

Assertion statements can be built with underscores and/or dots.

assert.is.True(true);           // Equivalent
assert.is_true(true);           // Equivalent

assert.is.not.True(false);      // Equivalent
assert.is_not_true(false);      // Equivalent

Verbs can be chained. However if there is a not or no within the chain, the assertion is expected to be fail. This cannot be reverted with another not or no.

assert.is.is.is.not.is.not.False(true);   // Assertion failed.
                                          // This was expected because of `not`

Async Tests

To use async() and done() make sure your test case is wrapped in a pending(...) call.

async(); // error, trying to call nil value
done(); // error, trying to call nil value

pending("waiting for sleep to complete", () => {
  async();
  sleep(5000);
  done();
});

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.