0

We have an amd/requirejs based web app. We came to a point to add a unit testing to our code. Googling returned that squireJs is best amd-require based mocking library. after installing, The problem is that we cant resolve the squirejs dependency. The issue seems so basic but we tried with both Mocha and Jasmine to use it, though it seems something we are forgetting to configure:

our js that we want to test looks basically like:

define(function employeeAndTagsPage(require) {  
    var global = require('common/global');
    var customMessageWindow = require('../../customMessageWindow/customMessageWindow');

    var currentTab;
    var navigate = null;
    // and other BL
});

Package.json:

{
  "name": "jasmine.test",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "MIT",
  "devDependencies": {
    "amd-loader": "0.0.8",
    "jasmine-node": "^3.0.0",
    "requirejs": "^2.3.6",
    "squirejs": "^0.2.1"
  }
}

Jasmine_examples PlayerSpec.js:

describe("Player", function () {
    require('amd-loader');
  var Player = require('../../lib/jasmine_examples/Player');
    var Song = require('../../lib/jasmine_examples/Song');
    var requirejs = require('requirejs');
    var squire = requirejs('squirejs'); // here it fails 
    var player, song,  mock;

  beforeEach(function() {
    player = new Player();
    song = new Song();
    mock = new squire();
  });
//unit tesitng 
});

The error we are getting:

ReferenceError: requirejs is not defined
  Stack:
        at <Jasmine>
        at getContext (c:\Synel\TESTS\eHarmonyNew-Jasmine\eHarmony\App\Test\node_modules\squirejs\src\Squire.js:58:5)
        at Squire.configure (c:\Synel\TESTS\eHarmonyNew-Jasmine\eHarmony\App\Test\node_modules\squirejs\src\Squire.js:107:15)

The squirejs library code can be found here:

https://github.com/iammerrick/Squire.js/blob/master/src/Squire.js

What is the reason of the library being failed ? What we are forgetting? Any assist or reccomendation is appraciated

4
  • Did you install dev dependencies? Try running npm install --dev Commented Feb 4, 2020 at 10:13
  • yes,i did. for all install, i add prefix --save-dev. and now i double checked by running the command
    – ISkandar
    Commented Feb 4, 2020 at 11:37
  • i believe i must inform you that i dont have any additional config or other files for requirejs. Might it be that it is the cause?
    – ISkandar
    Commented Feb 4, 2020 at 11:38
  • Try to use {{require}} instead of {{requirejs}} Commented Feb 7, 2020 at 12:47

0