2012-10-23 5 views
7

Sto appena iniziando a utilizzare QUnit e ad avere problemi.QUnit non eseguirà i test

Attualmente sto utilizzando TypeScript, che è un compilatore JavaScript. Ho le mie prove in classi che sono parallele alla struttura delle mie classi principali.

In ognuna di queste classi, ho una funzione chiamata runTests().

Per eseguire questi test, eseguo il loop e recupero tutte le classi che terminano in "Test", quindi chiamano la loro funzione runTests().

Un esempio dei runTests() è:

runTests = function() { 
    QUnit.test("5 = 5", function() { 
    QUnit.ok(5 == 5, "okay"); 
    }); 
} 

so che tutti i runTests() lavoro (come in essi sono chiamati, ha confermato a causa di uscita della console), ma al massimo è sempre e solo mi mostra un test. Sembra essere sempre l'ultimo test chiamato (anche con più test nello stesso runTests()).

C'è qualche cosa strana in cui QUnit si reimposta da solo ed è per questo che ne sto vedendo solo uno, o mi manca qualcosa di ancora più fondamentale?

Grazie.


Il codice HTML che uso è qui, nel caso in cui è importante:

<!DOCTYPE html> 
<html> 
<head> 
    <meta charset="utf-8"> 
    <title>QUnit Example</title> 
    <link rel="stylesheet" href="qunit-git.css"> 
</head> 
<body> 
<div id="qunit"></div> 
<script src="qunit-1.10.0.js"></script> 
<script src="mycode.js"></script> 
<script type="text/javascript"> 
    function runTest() { 
     var testClasses = getClassesRecurse(Test, []); 

     function getClassesRecurse(target, testClasses) { 
      if (typeof target == 'function' && /Test$/.test(target.name)) { 
       testClasses.push(target); 
      } else if (typeof target == 'object') { 
       for (var i in target) { 
        getClassesRecurse(target[i], testClasses); 
       } 
      } 

      return testClasses; 
     } 

     for (var i in testClasses) { 
      var testObj = new testClasses[i](); 

      if (testObj.runTests) { 
       console.log('Testing: ' + testClasses[i].name, testObj); 
       testObj.runTests(); 
      } 
     } 
    } 

    runTest(); 
</script> 
</body> 
</html> 
+0

jsfiddle, per favore. – c69

risposta

16

Quindi, per rispondere alla mia domanda: sembra che mi aveva colpito "replica" su un test ed è stato mostrando me solo un test. Rimozione della stringa di query e tutto è andato bene.

Un suggerimento a QUnit: aggiungere un messaggio in un grande carattere: "Esegui solo un test, fai clic qui per eseguire tutto." = p