09:39 7/6/26 Testing your JavaScript Plugins
menu
Documentation keyboard_arrow_right Tests
Tests
Overview
This guide provides instructions on integrating Jest to test your implementations using any
jSuites plugins.
Blueprint
The example below demonstrates a test where the render method of the mask plugin is
invoked, and the output is validated against the specified assertions.
1 describe('Testing [Link]', () => {
it('Render method', function() {
2 expect([Link](123, { mask: '00000'}, true)).toBe('00123');
expect([Link](11.45, { mask: '0.0' }, true)).toBe('11.5');
3 });
});
Testing Plugins That Use the DOM
Install the jsdom package to test plugins on HTML elements and validate their behavior. Once
configured, use the example below to verify if an element is added or removed from the
document body.
[Link] 1/3
09:39 7/6/26 Testing your JavaScript Plugins
describe('Testing [Link]', () => {
test('Testing if elements are being displayed in HTML', () => {
[Link] = '<div id="root"></div>';
let div = [Link]('root')
[Link](div, {
items: [
{
title: 'Select All',
shortcut: 'Ctrl + A',
tooltip: 'Method to Select All Text',
},
],
})
expect([Link]).toContain('Select All')
expect([Link]).toContain('Ctrl + A')
expect([Link]).toContain('Method to Select All
Text')
});
});
More examples in our GitHub repository
Running Your Tests
Create a ./test folder in your project root and include your test files.
Run the tests from the command line using:
npm run test
Troubleshooting
[Link] 2/3
09:39 7/6/26 Testing your JavaScript Plugins
Not possible to load a file outside the module
Issue: Unable to Load a File Outside the Module
This error occurs when using the import statement in a [Link] project without properly
configuring the module type in [Link]. [Link] defaults to CommonJS, causing issues
with ES module compatibility.
Solution:
To address this issue, follow these steps:
Open your [Link] file.
Add the 'type' field with the value 'module' as shown below:
{ "type": "module", // ... other [Link] configurations }
Save the [Link] file.
Run your tests.
Optionally, remove the type field from [Link] after testing.
This solution allows for proper module loading when working with ES modules and
CommonJS in [Link].
[Link] 3/3