ja najpierw chcę powiedzieć, że jestem nowy na RequireJS a nawet nowsze do Jasmine.Getting requirejs pracować z Jasmine
Mam pewne problemy z SpecRunner i wymagają JS. Śledziłem tutoriale Uzi Kilona i Bena Nadela (wraz z kilkoma innymi) i pomogli niektórym, ale wciąż mam pewne problemy.
Wydaje się, że jeśli nie ma błędu, który jest wyrzucany w teście (mogę myśleć o jeden w szczególności rodzaj błędu) spec biegacz html będą wyświetlane. To mówi mi, że mam pewne problemy w javascript. Jednak po usunięciu tych błędów żaden HTML nie jest już wyświetlany. Nie mogę w ogóle uruchomić testera. Czy ktoś może znaleźć coś nie tak z moim kodem, który spowodowałby ten problem?
Oto moja konstrukcja katalog:
Root
|-> lib
|-> jasmine
|-> lib (contains all of the jasmine lib)
|-> spec
|-> src
|-> jquery (jquery js file)
|-> require (require js file)
index.html (spec runner) specRunner.js
Oto SpecRunner (indeks) HTML:
<!doctype html>
<html lang="en">
<head>
<title>Javascript Tests</title>
<link rel="stylesheet" href="lib/jasmine/lib/jasmine.css">
<script src="lib/jasmine/lib/jasmine.js"></script>
<script src="lib/jasmine/lib/jasmine-html.js"></script>
<script src="lib/jquery/jquery.js"></script>
<script data-main="specRunner" src="lib/require/require.js"></script>
<script>
require({ paths: { spec: "lib/jasmine/spec" } }, [
// Pull in all your modules containing unit tests here.
"spec/notepadSpec"
], function() {
jasmine.getEnv().addReporter(new jasmine.HtmlReporter());
jasmine.getEnv().execute();
});
</script>
</head>
<body>
</body>
</html>
Oto specRunner.js (config)
require.config({
urlArgs: 'cb=' + Math.random(),
paths: {
jquery: 'lib/jquery',
jasmine: 'lib/jasmine/lib/jasmine',
'jasmine-html': 'lib/jasmine/lib/jasmine-html',
spec: 'lib/jasmine/spec/'
},
shim: {
jasmine: {
exports: 'jasmine'
},
'jasmine-html': {
deps: ['jasmine'],
exports: 'jasmine'
}
}
});
Oto specyfikacja:
require(["../lib/jasmine/src/notepad"], function (notepad) {
describe("returns titles", function() {
expect(notepad.noteTitles()).toEqual("");
});
});
Źródłem schowek:
define(['lib/jasmine/src/note'], function (note) {
var notes = [
new note('pick up the kids', 'dont forget to pick up the kids'),
new note('get milk', 'we need two gallons of milk')
];
return {
noteTitles: function() {
var val;
for (var i = 0, ii = notes.length; i < ii; i++) {
//alert(notes[i].title);
val += notes[i].title + ' ';
}
return val;
}
};
});
i źródłem Note (JIC):
define(function(){
var note = function(title, content) {
this.title = title;
this.content = content;
};
return note;
});
Zrobiłem pewien, że o ile aplikacja jest zaniepokojona, ścieżki są poprawne. Kiedy już to zrobię, mogę grać, konfigurując te ścieżki, aby nie było tak paskudnie.
można spróbować to? Zdefiniowany HtmlOdpowiedź poza wymaganiem. Zadzwoń tylko wykonaj wewnątrz. var jasmineEnv = jasmine.getEnv(); jasmineEnv.addReporter (new jaśmin.HtmlReporter()); require (['suites/aSpec.js'], function (spec) { jasmineEnv.execute(); }); – basos
Dla wersji autonomicznej Jasmine 2.0.0 ta odpowiedź zadziałała: http://stackoverflow.com/questions/19240302/does-jasmine-2-0-really-not-work-with-require-js/20851265#20851265 – shaunsantacruz