I am facing below issue while running mocha test via karma
Uncaught Error: Mismatched anonymous define() module: function (workflow) {
var expect = chai.expect;
describe('Empty Workflow Project Creation Module Testing', function () {
it('should throw an error if project is not empty', function () {
var result = [];
alert('check des');
result=workflow.onAfterGenerate("projectzip", "model");
// result = onAfterGenerate("projectzip", "model");
expect(result[0]).to.equal("projectzip");
expect(result[1]).to.equal("model");
});
});
}
http://requirejs.org/docs/errors.html#mismatch
at node_modules/requirejs/require.js:143
My karma conf file is :
module.exports = function(config) {
config.set({
basePath: '',
frameworks: ['requirejs','mocha','openui5'],
openui5: {
//path: 'https://sapui5.hana.ondemand.com/resources/sap-ui-core.js',
path: 'https://sapui5.hana.ondemand.com/1.30.8/resources/sap-ui-core.js',
useMockServer: false
},
files: [
{pattern: 'node_modules/**/*.js', included: false},
'test/test-main.js',
'js/spec/CreateEmptyWFProject_spec.js'
],
/* preprocessors: {
'src/test/js/fixtures/*.html': ['html2js'],
'src/*.js': ['coverage']
},*/
// reporters: ['progress', 'coverage','html'],
/*htmlReporter: {
outputFile: 'target/units.html',
// Optional
pageTitle: 'Unit Tests',
subPageTitle: 'A workflow project description',
groupSuites: true,
useCompactStyle: true,
useLegacyStyle: true
},*/
port: 8080,
colors: true,
autoWatch: true,
captureTimeout: 60000, // it was already there
browserDisconnectTimeout : 10000,
browserDisconnectTolerance : 1,
browserNoActivityTimeout : 60000,//by default 10000
browsers: ['Chrome'],
singleRun: true,
logLevel: config.LOG_INFO/*,
coverageReporter: {
dir: 'target/test_js_coverage',
instrumenter: {
'js/*.js': ['istanbul']
},
reporters: [
{ type: 'html', subdir: 'report-html' }
]
}*/
});
};
package.json looks like this
{
"name": "requirejs_mocha",
"version": "1.0.0",
"description": "check requirejs mocha karma",
"main": "index.js",
"scripts": {
"test": "echo "Error: no test specified" && exit 1"
},
"author": "",
"license": "ISC",
"devDependencies": {
"karma": "^1.7.0",
"karma-chrome-launcher": "^2.1.1",
"karma-mocha": "^1.3.0",
"karma-requirejs": "^1.1.0",
"requirejs": "^2.3.3"
}
}
Project structure :
![image](https://cloud.githubusercontent.com/assets/28787555/26499383/08a2f7b4-4250-11e7-97f0-dc93395fb5b9.png)
test-main.js is
/**
// if invoked in karma-runner environment
if (typeof window != 'undefined' && window.karma != undefined) {
// Karma serves files from '/base'
baseUrl = '/base';
requirejsCallback = window.karma.start;
// looking for *_spec.js files
specFiles = [];
for (var file in window.__karma__.files) {
if (window.__karma__.files.hasOwnProperty(file)) {
if (/.*\/js\/spec\/.+_spec\.js$/.test(file)) {
specFiles.push(file);
}
}
}
}
/** requirejs.config({
baseUrl: baseUrl,
paths: {
'chai': 'node_modules/chai/chai',
'sinon': 'node_modules/sinon/pkg/sinon'
},
// ask Require.js to load these files (all our tests)
deps: specFiles,
// start test run, once Require.js is done
callback: requirejsCallback
}); **/
requirejs.config({
baseUrl: '/base',
deps: specFiles,
callback: mocha.run
});
})();
Test file : CreateEmptyWFProject_spec
debugger;
alert('hello');
define(['../../src/workflow-tools/client/sap.bpm.webide.wfs.template.plugin/workflow/workflow'], function(workflow) {
var expect = chai.expect;
describe('Empty Workflow Project Creation Module Testing', function () {
it('should throw an error if project is not empty', function () {
var result = [];
alert('check des');
result=workflow.onAfterGenerate("projectzip", "model");
// result = onAfterGenerate("projectzip", "model");
expect(result[0]).to.equal("projectzip");
expect(result[1]).to.equal("model");
});
});
});
Thanks for help in advance