# Testing

# Unit test

# Installation

Ts.ED support officially two unit test frameworks: Jest and Mocha. It's also possible to use your preferred frameworks. Your feedback are welcome

    # Usage

    Ts.ED provides PlatformTest to create a new context to inject your Services, Controllers, Middlewares, etc... registered with annotations like Injectable .

    The process to test any components is the same thing:

    • Create a new context for your unit test with PlatformTest.create,
    • Inject or invoke your component with PlatformTest.inject or PlatformTest.invoke,
    • Reset the context with PlatformTest.reset.

    Here is an example to test the ParseService:

      # Async / Await

      Testing asynchronous method is also possible using Promises (async/await):

        # Mock dependencies

        PlatformTest API provides an invoke method to create a new instance of your component with mocked dependencies.


          PlatformTest.invoke() executes automatically the $onInit hook!

          # Test your Rest API

          # Installation

          To test your API, I recommend you to use the supertest (opens new window) module.

          To install supertest just run these commands:

            # Example


              If you use the PlatformTest, you'll probably get an error when you'll run the unit test:

              Platform type is not specified. Have you added at least `import @tsed/platform-express` (or equivalent) on your Server.ts ?

              To solve it, just add the import @tsed/platform-express on your Server.ts. PlatformTest need this import to know on which Platform your server must be executed for integration test.

              # Testing session

              To install session with Ts.ED see our tutorial.

                Last Updated: 1/14/2021, 10:28:24 AM

                Other topics