Search code examples
javascriptdojoqunit

Testing Dojos JsonRest using QUnit


I want to write integration tests against the Dojo JsonRest Store with QUnit. The test should verify that JsonRest integrates with a REST API I have written.

Currently I have the following code, copied from the QUnit website:

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width">
    <title>QUnit Example</title>
    <link rel="stylesheet" href="https://code.jquery.com/qunit/qunit-2.1.1.css">
</head>
<body>
    <!-- <script src="https://cdnjs.cloudflare.com/ajax/libs/dojo/1.10.4/dojo.js" data-dojo-config="async: true"></script> -->
    <div id="qunit"></div>
    <div id="qunit-fixture"></div>
    <script src="https://code.jquery.com/qunit/qunit-2.1.1.js"></script>
    <script>
         QUnit.test( "Teste ob Dojo's JsonRest mit der API kompatibel ist", 
            function( assert ) {
                    assert.ok( 1 == "1", "Passed!" );
            });
    </script>
</body>
</html>

This works perfectly well as long as the first script tag is commented out. It then displays a page page that shows that the test passed. However, if I include dojo by uncommenting said script tag, it just displays a blank page. There are no error messages and the I have verified, that all links to external files are valid and can be reached. I have also tried to load the js and css files from the same server and googling as well.

I have encountered this behavior with Firefox 50.1.0 and Chromium 55.0.2883.87 under Ubuntu 16.04.1. The webserver runs on localhost.


Solution

  • Move the dojo script tag to below the script tags for QUnit:

    <body>
      <div id="qunit"></div>
      <div id="qunit-fixture"></div>
      <script src="https://code.jquery.com/qunit/qunit-2.1.1.js"></script>
      <script>
         QUnit.test( "Teste ob Dojo's JsonRest mit der API kompatibel ist", 
            function( assert ) {
                    assert.ok( 1 == "1", "Passed!" );
            });
      </script>
      <script src="https://cdnjs.cloudflare.com/ajax/libs/dojo/1.10.4/dojo.js" data-dojo-config="async: true"></script>
    </body>