Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

131
Views
Getting Require and Jasmine to run together

I can't figure out how to get Require and Jasmine to work together.

What I'd like to do is just use Jasmine to write unit tests for some modules. I've got some small app that has a require config, and now I'm trying to load that same config into a Jasmine context but I get errors of different types.

Here's what I'm trying to do:

spec/myModuleTests.spec.js:

require(["/lib/require-init.js"], function (config) {
    require(['module1', 'module2'],
        describe("my TestCase", function () {
            it("isATrap", function() {
              expect(1).toEqual(2);
              });
            }))});

And that's what I get when I run npx jasmine:

TypeError [ERR_INVALID_ARG_TYPE]: The "id" argument must be of type string. Received an instance of Array
    at new NodeError (node:internal/errors:371:5)
    at validateString (node:internal/validators:119:11)
    at Module.require (node:internal/modules/cjs/loader:998:3)
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.<anonymous> (D:\.. ..spec.js:1:1)
    at Module._compile (node:internal/modules/cjs/loader:1101:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Module.require (node:internal/modules/cjs/loader:1005:19) {
  code: 'ERR_INVALID_ARG_TYPE'
}

Now, that wouldn't be nearly as weird if I didn't just copy that same code from the app.js, except that there's no "describe" for a test in there, but the actual app, where the code looks like this:

lib/app.js

require(["/lib/require-init.js"], function (config) {
    require(['module1', 'module2'],
                    console.log(module1);
                    module2.init();
                });
});

And that totally works - no errors at all.

All I'm doing with the "real" app is call it in the HTML:

<script data-main="/lib/app.js"
        src="/modules/vendor/requirejs/require-2.3.6.js"></script>

lib/require-init.js

require.config({
    baseUrl: './',
    paths: {
        module1: '/lib/module1',
        module2: '/lib/module2'
    }
});

What am I doing wrong?

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!