I have multiple tests that need to share the same common utilities script. I wouldn't want to place this file in the source folder structure, since it's only relevant for testing.
So my source folder is:
<jsSrcDir>${project.basedir}/src/main/js</jsSrcDir>
and my test source:
<jsTestSrcDir>src/test/js</jsTestSrcDir>
In src/test/js I have a testUtil.js file that I need to load in other jasmine tests. Is it possible to access such files from within a jasmine test?
describe('Load Util Module', function() {
it('check util is loaded', function() {
//load testUtil.js
});
});
This is how I managed to do it:
I added require.js to my specs folder
src/test/js/require.js
In the jasmine-maven-plugin configuration I added the REQUIRE_JS spec runner template:
<specRunnerTemplate>REQUIRE_JS</specRunnerTemplate>
The data file is located in:
src/test/js/testUtil.js
having the following content:
define([], function() {
return {
"data" : [1, 2, 3]
};
});
The tests to be injected this data object require a define directive:
define(['../../../spec/testUtil'], function(testUtil) {
var _testUtil = testUtil;
describe('Testing data loaded', function () {
it('loads test data', function () {
expect(testUtil.data.length).toBe(3);
});
});
});