Unit Test Case ARC-GIS Javascript

20 Views Asked by At

To do the unit test case I used the platform, jasmine for ARC-GIS Javascript.

npm install jasmine --save-dev

jasmine configuration files are installed and listed development dependency in your package.json file

npx jasmine init

This command creates a spec directory and a jasmine.json configuration file in the project

Then By adding the simple addition function in utility.js file

export function add(a, b) {
    return a + b;
  }

Unit test case function:

import { add } from '../libs/utility.js'; 

describe('Math Utility', () => {
  it('should add two numbers', () => {
    
    const num1 = 5;
    const num2 = 10;

    const result = add(num1, num2);

    expect(result).toEqual(15);
  });
}); 

Package.json:

{
  "name": "...",
  "private": ...,
  "version": "...",
  "type": "module",
  "scripts": {
    "dev": "...",
    "build": "...",
    "preview": "...",
    "cleancp": "...",
    "test": "jasmine"

  },
  "devDependencies": {
    "jasmine": "^5.1.0",
    "...": "..."
  },

To run the test case : npx jasmine

I got the error:

Error [ERR_MODULE_NOT_FOUND]: Cannot find module 'E:\path\to\libs\maplayers' imported from E:\path\to\libs\utility.js at new NodeError (internal/errors.js:322:7) at finalizeResolution (internal/modules/esm/resolve.js:318:11) at moduleResolve (internal/modules/esm/resolve.js:776:10) at Loader.defaultResolve [as _resolve] (internal/modules/esm/resolve.js:887:11) at Loader.resolve (internal/modules/esm/loader.js:89:40) at Loader.getModuleJob (internal/modules/esm/loader.js:242:28) at ModuleWrap. (internal/modules/esm/module_job.js:76:40) at link (internal/modules/esm/module_job.js:75:36) { code: 'ERR_MODULE_NOT_FOUND' }

Please suggest the solution how to solve the issue.

0

There are 0 best solutions below