4.0.5 • Published 5 years ago
@ts-ioc/unit v4.0.5
packaged @ts-ioc/unit
This repo is for distribution on npm
. The source for this module is in the
main repo.
@ts-ioc/unit
: unit testing framework, base on AOP, Ioc container.
version 2+ of tsioc
Install
npm install @ts-ioc/unit
npm install @ts-ioc/unit-console
// in browser
npm install @ts-ioc/platform-browser
// in server
npm install @ts-ioc/platform-server
add extends modules
use unit
import { Suite, BeforeEach, UnitTest, Test, After, AfterEach Assert, Expect, ExpectToken } from '@ts-ioc/unit';
import { ConsoleReporter } from '@ts-ioc/unit-console';
import { PromiseUtil } from '@ts-ioc/core';
@Suite('Unit Test')
export class SuiteTest {
// testContainer: AnyApplicationBuilder;
@BeforeEach()
async initTest() {
console.log('---------beofre test-----------');
}
@Test('assert test timeout', 200)
testTimeout() {
console.log('--------assert test timeout------');
let def = PromiseUtil.defer();
setTimeout(() => {
def.resolve('out time do...')
}, 300)
return def.promise;
}
@Test('assert test in time', 200)
testInTime() {
console.log('--------assert test in time------');
let def = PromiseUtil.defer();
setTimeout(() => {
def.resolve('in time do...')
}, 100)
return def.promise;
}
@Test('assert test in time', 200)
testInTime(assert: Assert) {
console.log('--------assert test in time------');
let def = PromiseUtil.defer();
setTimeout(() => {
def.resolve('in time do...')
}, 100)
assert.strictEqual('0', 0);
return def.promise;
}
@Test('expect test')
async testEqural(@Inject(ExpectToken) expect: Expect) {
await expect('true').toBe(true);
}
@AfterEach()
clean(){
//clean each data.
}
@After()
destory(){
}
}
support old TDD BDD style unit test.
- TDD-style interface:
suite('Array', function() {
suite('#indexOf()', function() {
suiteSetup(function() {
});
test('should return -1 when not present', function() {
});
test('should return the index when present', function() {
});
suiteTeardown(function() {
});
});
});
- BDD-style interface:
describe('Array', function(){
describe('Array#indexOf()', function() {
it('should return -1 when not present', function() {
// ...
});
it('should return the index when present', function() {
// ...
});
});
});
custom run test code
new UnitTest()
.use(ConsoleReporter)
.use(...) // your assert expect ...
.test(SuiteTest);
// match test file. will auto load class with @Suite decorator.
//.test('test/');
use command run test code
pk test [test/**/*.ts]
pk test //default load test/**/*.ts
//or
pk test test/**/*.ts
- test result:
Documentation is available on the @ts-ioc/unit docs site.
License
MIT © Houjun
4.0.5
5 years ago
4.0.4
5 years ago
4.0.3
5 years ago
4.0.2
5 years ago
4.0.1
5 years ago
4.0.0
5 years ago
4.0.0-rs2
5 years ago
4.0.0-rs1
5 years ago
4.0.0-rs
5 years ago
4.0.0-beta30
5 years ago
4.0.0-beta28
5 years ago
4.0.0-beta27
5 years ago
4.0.0-beta26
5 years ago
4.0.0-beta25
5 years ago
4.0.0-beta24
5 years ago
4.0.0-beta23
5 years ago
4.0.0-beta22
5 years ago
4.0.0-beta21
5 years ago
4.0.0-beta20
5 years ago
4.0.0-beta19
5 years ago
4.0.0-beta18
5 years ago
4.0.0-beta17
5 years ago
4.0.0-beta16
5 years ago
4.0.0-beta15
5 years ago
4.0.0-beta13
5 years ago
4.0.0-beta12
5 years ago
4.0.0-beta11
5 years ago
4.0.0-beta10
5 years ago
4.0.0-beta9
5 years ago
4.0.0-beta8
5 years ago
4.0.0-beta7
5 years ago
4.0.0-beta6
5 years ago
4.0.0-beta5
5 years ago
4.0.0-beta4
5 years ago
4.0.0-beta3
5 years ago