Products

Tests

LemonadeJS uses Mocha and Chai for unit testing, providing a streamlined way to test your components. You can run tests via command line or a browser environment.

Overview

Testing Blueprint

Tests in LemonadeJS follow a simple pattern where the test method shares the same context ('this') as the component, enabling direct access to component properties and state during assertions:

describe('Testing lemonadejs native events', () => {
    it('Onload event', function() {
        function Component() {
            this.value = null;
            this.test = 5;
            this.onload = () => {
                this.value = this.test;
            }
            return render => render`<h1>${this.value}</h1>`;
        }

        // Render the component and assert the return
        return render(Component).assert('5', function () {
            return this.el.textContent;
        })
    });
});

More examples in our GitHub repository

Running your tests

Via NPM

Create a test directory in your project root and add your test files. Run tests using:

npm run test

Troubleshooting

When running tests via command line, you might encounter "Unable to Load a File Outside the Module" error. This occurs due to Node.js module system constraints when mixing ES Modules (ESM) and CommonJS modules. Make sure your testing configuration properly handles module imports according to your project's module system.