Testing with Jest and Mock XP

Contents

This tutorial introduces you to the Jest testing framework, and how to integrate it in your 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:

  • Set up Jest in an existing Enonic XP app

  • Write a simple test without any mocks

  • Write a test mocking Globals

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

  • Write a test for server-side code using Mock XP

  • Write a test for client-side code

  • Set up Coverage with Github Actions

  • Colocate tests with the code they test


Contents

Contents