View source | Discuss this page | Page history | Printable version   

How to create Jest testcases



Jest is a testing framework created by Facebook and currently used as the default testing framework in create-react-app. Unlike Mocha, it is an opinionated test runner and provides its own assertion and mocking methods. The main advantage is that it runs out-of-the-box and has good integration with technologies like React, Babel or Typescript.


Since PR19Q3, with the inclusion of the new Linter and Formatter tools, nodejs and npm should be installed. All dependencies can be installed just by running:

npm install

Creating a Test Case

Unit tests should be created under a web-test folder and filename should be suffixed with .test.js.

Now you can require() your subject under test and start creating test cases. See Jest documentation for reference.

Sample test file

describe('org.openbravo.client.application - OB.Utilities.Date', () => {
  beforeEach(() => {
    // Execute this before each test
  afterEach(() => {
    // Execute this after each test
  it('The year where we should change century in 2 digits year format is 50', () => {
  // Describe blocks can be nested to group test cases
  describe('OB.Utilities.Date.normalizeDisplayFormat', () => {
    it('function works', () => {
      const normalizedFormat = OB.Utilities.Date.normalizeDisplayFormat('DD-MM-YYYY');
    it('function works with other input', () => {
      const normalizedFormat = OB.Utilities.Date.normalizeDisplayFormat('DD-MM-YY');

Run tests/coverage

To run all unit tests available in an Openbravo instance (both Core and all installed modules), run the following command:

npm test

Testing can be limited to a particular module adding the path at the end of the command:

npm test modules/

If, along with the test, you want to see a coverage report, run:

npm run coverage
Bulbgraph.png   Tests should be placed in web-test folder, and files should have the suffix .test.js.

This is a valid path for a test class:


Retrieved from ""

This page has been accessed 4,476 times. This page was last modified on 18 November 2019, at 16:04. Content is available under Creative Commons Attribution-ShareAlike 2.5 Spain License.