2016-07-25 106 views
0

我正在嘗試使用Qunit爲此html進行單元測試。我得到的錯誤是Uncaught SyntaxError: Unexpected token < in JSON at position 0。它指向<!DOCTYPE html>中的「<」顯然這不是JSON,但它認爲它是,但我不知道爲什麼。爲什麼index.html被視爲JSON?意外的令牌<位置0

<!DOCTYPE html> 
     <html> 
     <head> 
      <meta charset="utf-8"> 
      <meta name="viewport" content="width=device-width"> 
      <title>Pinpoint Test</title> 
      <link rel="stylesheet" href="https://code.jquery.com/qunit/qunit-2.0.0.css"> 

      <script type="text/javascript" src="https://code.jquery.com/qunit/qunit-2.0.0.js"></script> 
      <script type="text/javascript" src="lib/jquery-3.0.0.min.js"></script> 
      <script type="text/javascript" src="jshamcrest.js"></script> 
      <script type="text/javascript" src="core.js"></script> 
      <script type="text/javascript" src="integration.js"></script> 
      <script type="text/javascript" src="jsmockito-1.0.4.js"></script> 

      <script type="text/javascript" src="lib/handlebars-v4.0.5.js"></script> 
      <script type="text/javascript" src="bootstrap.min.js"></script> 

      <script src="pinpoint.js"></script> 
      <script src="pinpointTest.js"></script> 
     </head> 
     <body> 
      <div id="qunit"></div> 
      <div id="qunit-fixture"> 
      //a lot more html 
    </body> 
    </html 

它說Source: at window.onerror (https://code.jquery.com/qunit/qunit-2.0.0.js:322:11)

qunit-2.0.0.js:

// Cover uncaught exceptions 
    // Returning true will suppress the default browser handler, 
    // returning false will let it run. 
    window.onerror = function(error, filePath, linerNr) { 
     var ret = false; 
     if (onErrorFnPrev) { 
      ret = onErrorFnPrev(error, filePath, linerNr); 
     } 

     // Treat return value as window.onerror itself does, 
     // Only do our handling if not suppressed. 
     if (ret !== true) { 
      if (QUnit.config.current) { 


     if (QUnit.config.current.ignoreGlobalErrors) { 
        return true; 
       } 
       QUnit.pushFailure(error, filePath + ":" + linerNr); 
      } else { 
//322    QUnit.test("global failure", extend(function() { 
        QUnit.pushFailure(error, filePath + ":" + linerNr); 
       }, { validTest: true })); 
      } 
      return false; 
     } 

     return ret; 
    }; 

回答

0

我的猜測是,在你的HTML文件的末尾缺少>只是一個錯字在這個例子嗎?我認爲您可能需要將所有這些<script>標籤放在<body>而不是<head>的末尾...... QUnit希望<div id="qunit"></div>標籤能放入其UI,並且您的測試正在試圖在HTML之前運行永遠加載。試一試,但如果它不起作用,你可以簡化你的測試只是一個簡單的assert.equall(1, 1)看看是否有效?如果你想讓我們看看他們,你也可以用你的實際測試來更新這個問題。

相關問題