03 getting started - ranhs/soda-test GitHub Wiki

Note: this page describe how to get started when using mocha (for node project)
In the bottom of this page there are links for pages of getting started using jest or karma (for angular projects)

Installation

In order to write unit tests using soda-test you need to install it using the command:

npm install soda-test --save-dev

configuration

Since soda-test is based on mocha, you need to add in package.json in the scripts section the "test" script for running the tests, using the mocha command. In the following example we will run tests on any file that is ends with .test.js:

{
   ...
   "scripts": {
        "test": "mocha \"./{,!(node_modules)/**}/*.test.js\""
        ...
    }
    ...
}

Basic sample

The following code is a sample for a test that checks that 1+1 is 2:

import { expect, describe, it, TR } from 'soda-test'

@describe('Basic Sample')
class SampleCase {

    @it('validates that 1+1 is 2')
    sampleStep(): TR {
        expect(1+1).to.equal(2)
    }
}

Execution

To run the test, run the following command from the command prompt (or terminal):

npm run test

or

npm test

The result looks like this:

  Basic Sample
    √ validates that 1+1 is 2

  1 passing (10ms)

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