2016-11-27 2 views
0

Ich habe einen NodeJs-Client geschrieben, der API-Anfragen für verschiedene Kombinationen generiert und die Antworten in einem Array speichert. Indem ich eine Jasmine-Schriftstelle umschlinge, versuche ich, sie durchzusetzen. Meine Tests werden jedoch ausgeführt, bevor das API-Antwortarray initialisiert wird. Ich habe bisher zwei Ansätze probiert und bisher kein Glück.Jasmin-Looping-Tests

Ansatz 1:

var answersReq = require('../requests/answers_request'); 
 

 
var data = answersReq.answers(function(results) { 
 
\t return results; 
 
}) 
 

 
describe("Answer API test", function() { 
 

 
\t function runTest(context) { 
 
\t \t describe("test array suite", function() { 
 
\t \t \t it("test array", function(done) { 
 
\t \t \t \t expect(context).not.toBeNull(); 
 
\t \t \t \t done(); 
 
\t \t \t }); 
 
\t \t }); 
 
\t } 
 

 
\t for (i = 0; i <= data.length; i++) { 
 
\t \t runTest(data[i]); 
 
\t } 
 

 
});

Ansatz 2:

var answersReq = require('../requests/answers_request'); 
 

 
var data; 
 

 
describe("Answer API test", function() { 
 

 
\t beforeAll(function(done) { 
 
\t \t data = answersReq.answers(function(results) { 
 
\t \t \t data = results; 
 
\t \t \t done(); 
 
\t \t }) 
 
\t }); 
 

 
\t function runTest(context) { 
 
\t \t describe("test array suite", function() { 
 
\t \t \t it("test array", function(done) { 
 
\t \t \t \t expect(context).not.toBeNull(); 
 
\t \t \t \t done(); 
 
\t \t \t }); 
 
\t \t }); 
 
\t } 
 

 
\t for (i = 0; i <= data.length; i++) { 
 
\t \t runTest(data[i]); 
 
\t } 
 

 
});

Antwort

0

Werke für mich, überprüfen, was inist

/*** CODE ***/ 
 
var data = [1,1,1,1,1] 
 
describe("Answer API test", function() { 
 

 
\t function runTest(context) { 
 
\t \t describe("test array suite", function() { 
 
\t \t \t it("test array", function(done) { 
 
\t \t \t \t expect(context).not.toBeNull(); 
 
\t \t \t \t done(); 
 
\t \t \t }); 
 
\t \t }); 
 
\t } 
 

 
\t for (i = 0; i <= data.length; i++) { 
 
\t \t runTest(data[i]); 
 
\t } 
 

 
});
<link href="https://cdnjs.cloudflare.com/ajax/libs/jasmine/2.4.1/jasmine.min.css" rel="stylesheet"/> 
 
<script src="https://cdnjs.cloudflare.com/ajax/libs/jasmine/2.4.1/jasmine.min.js"></script> 
 
<script src="https://cdnjs.cloudflare.com/ajax/libs/jasmine/2.4.1/jasmine-html.min.js"></script> 
 

 
<script src="https://cdnjs.cloudflare.com/ajax/libs/jasmine/2.4.1/boot.min.js"></script>