6.0.48 • Published 1 year ago

@tsdi/unit-console v6.0.48

Weekly downloads
43
License
MIT
Repository
github
Last release
1 year ago

packaged @tsdi/unit-console

This repo is for distribution on npm. The source for this module is in the main repo.

@tsdi/unit-console: unit testing console reporter, base on AOP, Ioc container.

version 5+ of @ts-ioc/core tsioc

Install

npm install @tsdi/unit
npm install @tsdi/unit-console

// in browser
npm install @tsdi/platform-browser

// in server
npm install @tsdi/platform-server

add extends modules

use unit

import { Suite, BeforeEach, UnitTest, Test, After, AfterEach Assert, Expect, ExpectToken } from '@tsdi/unit';
import { ConsoleReporter } from '@tsdi/unit-console';
import { PromiseUtil } from '@tsdi/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

  • use runTest to run
// run Test
/**
 * unit test.
 *
 * @export
 * @param {(string | Type | (string | Type)[])} src test source.
 * @param {(string | AppConfigure)} [config] test configure.
 * @param {...LoadType[]} deps custom set unit test dependencies.
 * @returns {Promise<any>}
 */
export function runTest(src: string | Type | (string | Type)[], config?: string | UnitTestConfigure, ...deps: LoadType[]): Promise<any>;

runTest(SuiteTest, {...}, ConsoleReporter);
  • use boot application
import { BootApplication, DIModule, ConfigureRegister } from '@tsdi/boot';
import { UnitTest } from '@tsdi/unit';

BootApplication.run(UnitTestContext.parse({ module: UnitTest, deps: [ConsoleReporter], configures: [config, { src: src }] }))

use command run test code

tsdi test [test/**/*.ts]

tsdi test  //default load test/**/*.ts

//or
tsdi test test/**/*.ts
  • test result: image

Documentation

Documentation is available on the

packages

@tsdi/cli @tsdi/ioc @tsdi/aop @tsdi/core @tsdi/boot @tsdi/components @tsdi/compiler @tsdi/activities @tsdi/pack @tsdi/typeorm-adapter @tsdi/unit @tsdi/unit-console

License

MIT © Houjun

6.0.48

1 year ago

6.0.47

1 year ago

6.0.46

1 year ago

6.0.45

1 year ago

6.0.44

2 years ago

6.0.43

3 years ago

6.0.42

3 years ago

6.0.41

3 years ago

6.0.40

3 years ago

6.0.39

3 years ago

6.0.38

3 years ago

6.0.37

3 years ago

6.0.36

3 years ago

6.0.35

3 years ago

6.0.33

3 years ago

6.0.32

4 years ago

6.0.31

4 years ago

6.0.30

4 years ago

6.0.29

4 years ago

6.0.28

4 years ago

6.0.27

4 years ago

6.0.26

4 years ago

6.0.25

4 years ago

6.0.24

4 years ago

6.0.23

4 years ago

6.0.22

4 years ago

6.0.21

4 years ago

6.0.20

4 years ago

6.0.19

4 years ago

6.0.18

4 years ago

6.0.16

4 years ago

6.0.17

4 years ago

6.0.15

4 years ago

6.0.13

4 years ago

6.0.12

4 years ago

6.0.11

4 years ago

6.0.10

4 years ago

6.0.9

4 years ago

6.0.8

4 years ago

6.0.7

4 years ago

6.0.6

4 years ago

6.0.4

4 years ago

6.0.3

4 years ago

6.0.2

4 years ago

6.0.1

4 years ago

6.0.0

4 years ago

6.0.0-beta12

4 years ago

6.0.0-beta11

4 years ago

6.0.0-beta9

4 years ago

6.0.0-beta8

4 years ago

6.0.0-beta7

4 years ago

6.0.0-beta6

4 years ago

6.0.0-beta5

4 years ago

6.0.0-beta4

4 years ago

6.0.0-beta3

4 years ago

6.0.0-beta2

4 years ago

6.0.0-beta1

4 years ago

5.3.13

4 years ago

5.3.12

4 years ago

5.3.11

4 years ago

5.3.10

4 years ago

5.3.9

4 years ago

5.3.8

4 years ago

5.3.7

5 years ago

5.3.6

5 years ago

5.3.5

5 years ago

5.3.3

5 years ago

5.3.2

5 years ago

5.3.1

5 years ago

5.3.0

5 years ago

5.3.0-beta4

5 years ago

5.3.0-beta3

5 years ago

5.3.0-beta2

5 years ago

5.3.0-beta1

5 years ago

5.3.0-beta

5 years ago

5.2.16

5 years ago

5.2.15

5 years ago

5.2.14

5 years ago

5.2.13

5 years ago

5.2.12

5 years ago

5.2.10

5 years ago

5.2.9

5 years ago

5.2.8

5 years ago

5.2.7

5 years ago

5.2.6

5 years ago

5.2.5

5 years ago

5.2.4

5 years ago

5.2.3

5 years ago

5.2.2

5 years ago

5.2.1

5 years ago

5.2.0

5 years ago

5.1.19

5 years ago

5.1.18

5 years ago

5.1.17

5 years ago

5.1.16

5 years ago

5.1.15

5 years ago

5.1.14

5 years ago

5.1.13

5 years ago

5.1.12

5 years ago

5.1.11

5 years ago

5.1.10

5 years ago

5.1.9

5 years ago

5.1.8

5 years ago

5.1.7

5 years ago

5.1.6

5 years ago

5.1.5

5 years ago

5.1.4

5 years ago

5.1.3

5 years ago

5.1.2

5 years ago

5.1.1

5 years ago

5.1.0

5 years ago

5.0.25

5 years ago

5.0.24

5 years ago

5.0.23

5 years ago

5.0.22

5 years ago

5.0.21

5 years ago

5.0.20

5 years ago

5.0.19

5 years ago

5.0.18

5 years ago

5.0.18-beta

5 years ago

5.0.1-8.beta

5 years ago

5.0.15

5 years ago

5.0.13

5 years ago

5.0.12

5 years ago

5.0.11

5 years ago

5.0.10

5 years ago

5.0.8

5 years ago

5.0.7

5 years ago

5.0.6

5 years ago

5.0.5

5 years ago

5.0.4

5 years ago

5.0.3

5 years ago

5.0.2

5 years ago

5.0.1

5 years ago

5.0.0

5 years ago

5.0.0-beta25

5 years ago

5.0.0-beta24

5 years ago

5.0.0-beta23

5 years ago

5.0.0-beta22

5 years ago

5.0.0-beta20

5 years ago

5.0.0-beta19

5 years ago

5.0.0-beta18

5 years ago

5.0.0-beta17

5 years ago

5.0.0-beta16

5 years ago

5.0.0-beta15

5 years ago

5.0.0-beta14

5 years ago

5.0.0-beta12

5 years ago

5.0.0-beta11

5 years ago

5.0.0-beta10

5 years ago

5.0.0-beta9

5 years ago

5.0.0-beta8

5 years ago

5.0.0-beta7

5 years ago

5.0.0-beta6

5 years ago

5.0.0-beta5

5 years ago

5.0.0-beta4

5 years ago

5.0.0-beta3

5 years ago

5.0.0-beta2

5 years ago

5.0.0-beta1

5 years ago

5.0.0-beta

5 years ago

4.0.5

5 years ago