Dove posso mettere gli apparecchi HTML quando sto usando JStestDriver?
-
28-10-2019 - |
Domanda
Sto facendo fatica a far caricare JSTD a caricare un file HTML del dispositivo.
La mia struttura di directory è:
localhost/JsTestDriver.conf
localhost/JsTestDriver.jar
localhost/js/App.js
localhost/js/App.test.js
localhost/fixtures/index.html
Il mio file conf dice:
server: http://localhost:4224
serve:
- fixtures/*.html
load:
- http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js
- jasmine/lib/jasmine-1.1.0/jasmine.js
- jasmine/jasmine-jquery-1.3.1.js
- jasmine/jasmine-jstd.js
- js/App.js
test:
- js/App.test.js
Il mio test è:
describe("App", function(){
beforeEach(function(){
jasmine.getFixtures().fixturesPath = 'fixtures';
loadFixtures('index.html'); **//THIS LINE CAUSES IT TO FAIL**
});
describe("When App is loaded", function(){
it('should have a window object', function(){
expect(window).not.toBe(null);
});
});
});
E la mia output della console è:
(Link all'immagine a grandezza naturale)
Ho guardato questa domanda Ma non mi ha aiutato a capirlo. La cosa strana è, quando commento il
loadFixTures ('index.html');
Linea, il test passa.
Qualche idea?
Soluzione
Ok, ho capito. JStestDriver prepara il "test" sul percorso dei tuoi infissi.
Inoltre, Jasmine-JQuery ottiene infissi usando l'Ajax.
Quindi, questi passaggi hanno finalmente funzionato per me:
In jstestdriver.conf:
serve:
- trunk/wwwroot/fixtures/*.html
load:
- trunk/wwwroot/js/libs/jquery-1.7.1.min.js
- jstd/jasmine/standalone-1.2.0/lib/jasmine-1.2.0/jasmine.js
- jstd/jasmine-jstd-adapter/src/JasmineAdapter.js
- jstd/jasmine-jquery/lib/jasmine-jquery.js
- trunk/wwwroot/js/main.js
test:
- trunk/wwwroot/js/main.test.js
Nel mio file di test:
describe("main", function(){
beforeEach(function(){
jasmine.getFixtures().fixturesPath = '/test/trunk/wwwroot/fixtures';
jasmine.getFixtures().load('main.html');
});
describe("when main.js is loaded", function(){
it('should have a div', function(){
expect($('div').length).toBe(1);
});
});
});
Nota che il beforeEach()
La chiamata utilizza un URL assoluto al dispositivo HTML.
Altri suggerimenti
Prova a cambiare il percorso del dispositivo a:
jasmine.getFixtures().fixturesPath = '/fixtures';
Altrimenti ottengo errori diversi, ma allo stesso modo strani.