New tutorial for writing tests for Enonic projects

Enonic proudly presents new tutorial for helping Enonic XP developers write tests (in Typescript or Javascript) using Jest framework and our very own Mock XP library.

Please welcome: Testing with Jest and Mock XP - Enonic Developer Portal

Enjoy and let us know if anything is unclear or if you think the tutorial needs any improvements.

4 Likes

I am getting this in VS Code:
image
The error message says:
“Cannot find module ‘./tsup/constants’ or its corresponding type declarations.”
Does anyone know what’s missing?

Hi there!
Are you using the tutorial and starter, or modifying an existing app?

Modifying an existing app.

The tutorial assumes that you are using the tutorial’s repository (tutorial-intro) which has all the prerequisites for the build.

If you want to migrate the tutorial’s setup to your own app then you have to make sure your app is set up to be built in exactly the same way as the tutorial’s repository, for example you have to install tsup, copy over “tsup” folder from the tutorial repository, make sure you are using exactly the same paths etc. Which you don’t necessarily have to do.

I suggest you go through the tutorial first to understand the concept of creating tests for XP apps. This will help you create tests in your own app without having to replicate the build setup from the tutorial.

We will discuss adding a new chapter which explains how to configure test runs in an existing app.

2 Likes

I did modify some files, so tutorial-jest is the repo guaranteed to have all files.

We might have to update the docs.

1 Like

There are more differences between tutorial-intro and tutorial-jest

Using this should work:

enonic project create com.example.tutorial.jest -r tutorial-jest -d jest-tutorial