Testing with Jest and Mock XP

Contents

This tutorial introduces you to the Jest testing framework, and how to integrate it in an Enonic application.

Introduction

Jest is a highly adopted testing framework that supports TypeScript, mocking, and a lot, lot more.

A special feature of this setup is that tests can be executed standalone, independently of Enonic XP. Thus, the tests will finish faster and be more flexible to execute.

For more details, visit the Jest documentation.

This guide will show you how to:

  1. Create a Project with Jest environment already set up.

  2. Write a simple test without any mocks

  3. Write a test for server-side code manually mocking Java libraries

  4. Write a test for server-side code using Mock XP

  5. Write a test for client-side code

Advanced topics

In addition to the main topics, you might want to learn about these advanced topics:

Additional reading

If you want to learn how to add Jest to an existing project, read the Testing chapter of the TypeScript Starter documentation.


Contents

Contents