<html> <head> <title>Unit tests</title> <link href="../../node_modules/mocha/mocha.css" rel="stylesheet" type="text/css" /> </head> <body> <script src="../../config/dojo.test.config.js"></script> <script src="//js.arcgis.com/3.7compact/"></script> <div id="mocha"></div> <script> require(["../../node_modules/chai/chai.js", "../../node_modules/mocha/mocha.js", "../../node_modules/sinon/lib/sinon.js"], function (chai) { mocha.setup('bdd'); mocha.reporter('html'); expect = chai.expect; require(["test/unit/MapApp"], function () { if (window.mochaPhantomJS) { mochaPhantomJS.run(); } else { mocha.run(); } }); }); </script> </body> </html>
Solved! Go to Solution.
<div id="mocha"></div> <div id="map"></div> <script type='text/javascript' src='//js.arcgis.com/3.7'></script> <script type="text/javascript" src="node_modules/mocha/mocha.js"></script> <script type="text/javascript" src="node_modules/chai/chai.js"></script> <script type='text/javascript' src='lib/sinon-1.7.3.js'></script> <!-- source files --> <script type="text/javascript" src="spec/main.js"></script> <script> var dojoConfig = { isDebug: false, has: {'dojo-undef-api': true} }; mocha.setup('bdd'); mocha.ignoreLeaks(); </script>
(function () { /** packages and configuration stuff **/ /** * Method same as with requirejs * http://www.bennadel.com/blog/2393-Writing-My-First-Unit-Tests-With-Jasmine-And-RequireJS.htm **/ require([ 'require', 'dojo/ready' ], function (require, ready) { ready(function () { require([ ], function () { (window.mochaPhantomJS || window.mocha).run(); }); }); }); })(this);
has: {'dojo-undef-api': true}
<script type="text/javascript" src="spec/main.js"></script> <script> var dojoConfig = { isDebug: false, isJasmineTestRunner: true, // prevents parser in main.js from running has: {'dojo-undef-api': true} }; mocha.setup('bdd'); mocha.ignoreLeaks(); </script>
/** * Method same as with requirejs * http://www.bennadel.com/blog/2393-Writing-My-First-Unit-Tests-With-Jasmine-And-RequireJS.htm **/ require([ 'require', 'dojo/ready' ], function (require, ready) { ready(function () { require([ /* helper modules */ 'spec/js/helpers/sampleHelperSpec' ], function () { (window.mochaPhantomJS || window.mocha).run(); }); }); });
require(["../../node_modules/chai/chai.js", "../../node_modules/mocha/mocha.js", "../../node_modules/sinon/lib/sinon.js"], function (chai) { mocha.setup('bdd'); mocha.reporter('html'); expect = chai.expect; require(["test/unit/MapApp"], function () { if (window.mochaPhantomJS) { mochaPhantomJS.run(); } else { mocha.run(); } }); });
<script src="../../config/dojo.test.config.js"></script> <script src="//js.arcgis.com/3.7compact/"></script>
var dojoConfig = { paths: { 'jscore': location.pathname.replace(/\/[^/]+$/, '') + '/../../node_modules/jscore', 'widgets': location.pathname.replace(/\/[^/]+$/, '') + '/../../node_modules/widgets', 'text': location.pathname.replace(/\/[^/]+$/, '') + '/../../node_modules/jscore/require/text', 'styles': location.pathname.replace(/\/[^/]+$/, '') + '/../../node_modules/jscore/require/styles', 'template': location.pathname.replace(/\/[^/]+$/, '') + '/../../node_modules/jscore/require/template', 'mapapp': location.pathname.replace(/\/[^/]+$/, '') + '/../../src/mapapp', 'test': location.pathname.replace(/\/[^/]+$/, '') + '/../../test' } };
define(["mapapp/MapApp"], function (MapApp) { 'use strict'; describe("MapApp", function () { it("MapApp should be defined", function () { expect(MapApp).not.to.be.undefined; }); }); });