项目作者: hazzard993

项目描述 :
TypeScript declarations for Busted (lua)
高级语言:
项目地址: git://github.com/hazzard993/busted-tstl.git
创建时间: 2019-02-23T03:19:43Z
项目社区:https://github.com/hazzard993/busted-tstl

开源协议:

下载


TypeScript declarations for Busted

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

You can install these via npm.

  1. yarn add -D busted-tstl
  2. # or
  3. 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.

  1. {
  2. "compilerOptions": {
  3. "lib": ["esnext"],
  4. "types": [
  5. "busted-tstl",
  6. "lua-types/5.1
  7. ]
  8. }
  9. }

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

  1. describe("mocks", () => {
  2. it("replaces a table with spies", () => {
  3. const t = {
  4. thing: function (this: void, msg) { print(msg) }
  5. };
  6. const m = mock(t); // mocks the table with spies, so it will print
  7. m.thing("Coffee");
  8. assert.spy(m.thing).was.called_with("Coffee");
  9. });
  10. it("replaces a table with stubs", () => {
  11. const t = {
  12. thing: function (this: void, msg) { print(msg) }
  13. };
  14. const m = mock(t, true); // mocks the table with stubs, so it will not print
  15. m.thing("Coffee");
  16. assert.stub(m.thing).was.called_with("Coffee");
  17. mock.revert(m); // reverts all stubs/spies in m
  18. m.thing("Tea"); // DOES print 'Tea'
  19. });
  20. });

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

  1. tstl spec/test_spec.ts
  2. tstl -p tsconfig.json
  3. 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.

  1. assert.is.True(true); // Equivalent
  2. assert.is_true(true); // Equivalent
  3. assert.is.not.True(false); // Equivalent
  4. 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.

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

Async Tests

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

  1. async(); // error, trying to call nil value
  2. done(); // error, trying to call nil value
  3. pending("waiting for sleep to complete", () => {
  4. async();
  5. sleep(5000);
  6. done();
  7. });