soda-test
TypeScript icon, indicating that this package has built-in type declarations

2.1.2 • Public • Published

Soda-Test
Soda -test

This package is easiest way to write unit-test.
We have gathered all the features you need from various packages, enhance them, and put them all into one, easy to use package.
You can learn to write unit test using soda-test package by going over soda-test documentation.
Write your unit-tests using typescript, with classes, decorators and promises.
Use the "spies" and "stubs" of the sinon package, but with soda-test easy to use syntax. No need to worry about cleanups, soda-test package do this for you.
Your tests are defined as functions in a class, and not as endless nested call-backs.
When writing unit-tests you may encounter the need to access or stub private or hidden function, stub middleware, avoid your code from accessing external packages that may access the web or databases. Doing that and other cases, with the traditional test packages, may be very difficult, if possible at all. Soda-test solves those issues the easy way, in some cases without you even knowing about those difficulties, and without the need to change your product code.
The syntax of unit test code with soda-test is easy to write and easy to understand.
Soda-test supports unit-test for frontend as well as for backend, with the same syntax.
Furthermore, soda-test gives you a framework for writing your API test.

And now, Soda-Test supports Angular Integration tests.



Installation

via npm

$ npm install soda-test --save-dev



Usage

In your project write your test files under test folder, or side by side with your project files, name them *.spec.ts
In your test file, define a class with describe decorator, and in it write your test methods with it decorator
use spies and stubs by defining member variables or arguments with decorators.
@describe('demo')
class TestDemoTest {

    @stub(User, "findById").returns("dummy-user")
    findStub: SinonStub

    @it('should get user by id')
    GetById(): TR {
        const user = getUser({id:123})
        expect(user).to.equal("dummy-user")
        expect(this.findStub).to.have.been.calledOnce.calledWith(123)
    }

}

For full documentation and many sample test, see soda-test wiki

Define API test-cases by using the testCase decorator on a method, and define its steps in it

   @testCase("sample case", SampleTestStepsTest)
   checkGetApi(step: stepMethod<SampleTestStepsTest>): void {
       step("define dummy REST server").StartRestServer({expect: "GET /", return: "dummy"})
       step("send get request").SendRequest({method:"GET", url: "/", expectresponse: "dummy"})
       step("validate get request").ValidateRequest({method: "GET", url: "/"})
       step("stop dummy Rest server").StopRestServer()
   }

For more details about API test case see Soda-test test-cases documenation



Goals

  • Write Your unit test in a type-script way (e.g. classes, decorators, promises)
  • Your test may be run under mocha, jest or Karma
  • All relevant packages are included and exported from one place (chai, sinon, super-test, etc...)
  • Using sinon library to create spies and stubs
  • Define sinon as class member or method argument
  • Sinons clean-up are done automatically, don't need to worry about it
  • Divide your test method to different contexts in the same test class
  • Stub and spy cases in an easy way the difficult cases
  • "rewire" is used under the hood. you don't need to worry about it
  • "rewire" works also when testing angular (using Jest or Karam) as well as when testing NodeJS projects
  • easy access to private methods in a module for testing and stubbing
  • can call/stub abstract and/or private methods in class for unit-testing
  • Use sinon fake timers to simulate time features without waiting the time during the unit tests
  • Also support API tests by using test-cases and test-steps method
  • Test steps can be reused in the same test-case or in different test-case with different arguments



Summary

Soda-Test helps you write good unit and API tests with high coverage.



Documentation

Soda-test has full documentation with sample code.
To learn using soda-test, you don't need to have previous knowledge of mocha, chai, or jasmine.
You do need knowledge of typescript.
It is recommended to go over the documentation in GitHub wiki, by its order

Following are all the pages available in GitHub wiki:

Sample Code

The following GitHub repositories holds sample codes for soda-test:

Install

npm i soda-test

DownloadsWeekly Downloads

71

Version

2.1.2

License

MIT

Unpacked Size

280 kB

Total Files

73

Last publish

Collaborators

  • ranhs