@ts-ioc/unit-console
v4.0.5
Published
unit testing console reporter
Downloads
13
Maintainers
Readme
packaged @ts-ioc/unit-console
This repo is for distribution on npm
. The source for this module is in the
main repo.
@ts-ioc/unit-console
: unit testing console reporter, 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-console docs site.
License
MIT © Houjun