@xxxxst/tsunit
v0.0.1
Published
typescript util test
Downloads
7
Readme
tsunit
a typescript unit test like csharp
https://github.com/xxxxst/tsunit
speciality
- pretty API
- run in chrome
- easy to locate the error
- support async test
npm install @xxxxst/tsunit
- enable decortor
- enable source map
see more at the example
https://github.com/xxxxst/example-tsunit
test file - ComTest.ts
@TestClass()
export default class ComTest {
@Test()
matchTest() {
Assert.equal(1, 1);
Assert.notEqual("aa", "bb");
}
@Ignore()
@Test()
ignoreTest() {
Assert.equal(1, 2, "info");
}
@Test(1, 2)
@Test("a", "b")
noMatchTest(except, actual) {
Assert.equal(except, actual, "info");
}
@AsyncTest()
async asyncTest() {
var rst = await this.getHttp();
Assert.equal("data", rst);
}
async getHttp() {
return new Promise(resolve => setTimeout(()=>{
resolve("data");
}, 0));
}
}
test file - ComTest2.ts
@TestClass({autoRun:false})
export default class ComTest2 {
constructor(arg1, arg2) {
}
}
entry point file
// dont't need to create the test class
import './ComTest';
// second way to import
// make sure the class is used
import ComTest from './ComTest';
ComTest
// run test by yourself
import ComTest2 from './ComTest2';
// ... your init code
setTimeout(()=>{
// run test
Assert.run(ComTest2, "arg1", "arg2");
}, 0);
open console to view test info
decorators
@TestClass(option?:{autoRun?:boolean}, ...args)
- class decorator
- mark test class
autoRun
auto run test, default istrue
args
test class constructor arguments
@Test(...args)
- function decorator
- mark test function
args
arguments
@AsyncTest(...args)
- function decorator
- mark asynchronous test function
- need to use
async/await
args
arguments
@Ignore()
- function decorator
- ignore (async) test function
Assert
Assert.run(class, ...args)
- run class by yourself
- need tu use
autoRun:false
in @TestClass() class
test class-
args
test class constructor arguments
Assert.setLang(obj)
- set language, default is english
obj
language key/map, see more at source code- build-in language:
Assert.lang_en_us
englishAssert.lang_zh_cn
chinese
Assert.equal(expected:any, actual:any, desc: string = "")
- assert if is equal, compare each param if is
object
expected
expected valueactual
actual valuedesc
describe info
orther assert
-|- :-|:- Assert.equal | (expected:any, actual:any, desc: string = "") Assert.notEqual | (expected:any, actual:any, desc: string = "") Assert.strongEqual | (expected:any, actual:any, desc: string = "") Assert.strongNotEqual | (expected:any, actual:any, desc: string = "") Assert.same | (expected:any, actual:any, desc: string = "") Assert.notSame | (expected:any, actual:any, desc: string = "") Assert.isTrue | (actual:any, desc: string = "") Assert.isFalse | (actual:any, desc: string = "") Assert.isEmpty | (actual:any, desc: string = "") Assert.isNotEmpty | (actual:any, desc: string = "") Assert.isNull | (actual:any, desc: string = "") Assert.isNotNull | (actual:any, desc: string = "") Assert.isUndefined | (actual:any, desc: string = "") Assert.isNotUndefined | (actual:any, desc: string = "") Assert.isBool | (actual:any, desc: string = "") Assert.isArray | (actual:any, desc: string = "") Assert.isObject | (actual:any, desc: string = "") Assert.isString | (actual:any, desc: string = "") Assert.isNumber | (actual:any, desc: string = "") Assert.success | (desc: string = "") Assert.fail | (desc: string = "")
assert usage
base on webpack + typescript + vue(ui test)