qfx-busted-tstl
v0.1.3
Published
TypeScript definitions for the Busted testing suite
Downloads
7
Readme
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();
});