07 context - ranhs/soda-test GitHub Wiki

You can divide the test-class into contexts. Each context may include once or more test-step methods. By specifing the context decorator with a string argument of the context name (decription) you are string a new context in the class, that will be affected until the next context decorator. Note that test-steps defined in the class before the first context decorator do not belong to any context, or you can say they belong to the global context of the test-class.

import { expect, describe, context, it, TR, PTR, Done } from 'soda-test'
import { add, addCallbck, addPromise, dividePromise } from './demo'

@describe('demo')
class TestDemo {

@context('add')

    @it('should add two numbers')
    addBasic(): TR {...}

@context('callback add')

    @it('should test the callback')
    addWithCallback(done: Done): TR {...}


@context('test promise')

    @it('should add with promise cb')
    addWithPromise(done: Done): TR {...}

    @it('should test a promise with return')
    addReturnAPromise(): Promise<TR> {...}

    @it('should test a promise with async await')
    async addWithAsyncAwait(): PTR {...}

    @it('should test a promise with chai-as-promise')
    async addWithChaiAsPromise(): PTR {

@context('divide')

    @it('should test a promise with chai-as-promise (divide success)')
    async divideSuccess(): PTR {...}

    @it('should test a promise with chai-as-promise (divide fails)')
    async divideFails(): PTR {...}
}

When execting the test-code, the test-step divide to their context in the output:

  demo
    add
      √ should add two numbers
    callback add
      √ should test the callback (502ms)
    test promise
      √ should add with promise cb
      √ should test a promise with return
      √ should test a promise with async await
      √ should test a promise with chai-as-promise
    divide
      √ should test a promise with chai-as-promise (divide success)
      √ should test a promise with chai-as-promise (divide fails)

⚠️ **GitHub.com Fallback** ⚠️