2015-05-22 6 views
5

Come da documentazione, possiamo avere gruppi gruppi-sub di suite di test, ma esiste solo in un unico file, come di seguitoCome raggruppare le suite di test in gelsomino quando i test esistono in file diversi?

describe('Main Group - Module 1', function() { 

    beforeEach(function() { 
     module('app'); 
    }); 

    describe('sub group - 1', function() { // Sub group   
     // specs goes here 
    }); 

    describe('sub group - 2', function() { // Sub group  
     // specs goes here 
    }); 
}); 

Se voglio mantenere gruppo sub -1 & sub gruppo -2 in due file diversi, come posso raggruppare questi due sottogruppi in Main Group - Module?

Grazie

+0

Purtroppo quello che stai chiedendo non è attualmente possibile, anche se è più di una limitazione di javascript piuttosto che di gelsomino. In questo modo non è possibile dichiarare una funzione su più file. –

+0

Quale versione di Jasmine stai correndo? – Adam

risposta

2

È possibile effettuare le seguenti operazioni:

file1.js

describe('Main Group - Module 1', function() { 

    beforeEach(function() { 
     module('app'); 
    }); 

    describe('sub group - 1', function() { // Sub group   
     // specs goes here 
    }); 

}); 

file2.js

describe('Main Group - Module 1', function() { 

    beforeEach(function() { 
     module('app'); 
    }); 

    describe('sub group - 2', function() { // Sub group  
     // specs goes here 
    }); 
}); 

Privacy lo stesso nome genitore.

+0

Ho provato questo, ma quando il report del caso di test viene generato, verrà visualizzato come due diversi gruppi. :( –

+0

Questo funziona per me - @ShivKumar, ti sei assicurato che le descrizioni siano identiche? –

+0

Sì Kevin, effettivamente uso karma-html segnalato per generarlo. –

1

Il mio caso d'uso per questo è Jasmine-Node, quindi le dichiarazioni require non fanno alcuna differenza per me. Se stai facendo Jasmine basato su browser, dovrai utilizzare RequireJS per questa soluzione. In alternativa, senza richiedere istruzioni, è possibile utilizzare this example from the Jasmine repo issues.

file1.js

module.exports = function() { 
    describe('sub group - 1', function() { // Sub group   
     // specs goes here 
    }); 
}; 

file2.js

module.exports = function() { 
    describe('sub group - 2', function() { // Sub group   
     // specs goes here 
    }); 
}; 

file3.js

var subgroup1 = require('./file1.js'); 
var subgroup2 = require('./file2.js'); 

describe('Main Group - Module 1', function() { 

    beforeEach(function() { 
     module('app'); 
    }); 

    subgroup1(); 
    subgroup2(); 
});