0
私はJavascriptを学び、Jasmineを使ってテストしています。私は2つのファイルを持っています。ファイルには詳細があります。この特定のセクションは機能しません。テストを実行すると、「NANが10になることを期待しています」というメッセージが表示されません。私はCounter.jsからtotalCountを取得してMyProject.jsを計算したいと思っていました。誰もこれで私を助けることができますか?1つのjavascriptファイルから別のjavascriptファイルのプロトタイプメソッドにプロトタイプメソッドの値を取得する方法は?
Counter.js
function Counter(){
this.count = 0;
}
Counter.prototype.startCount = function(count){
this.count += count;
};
Counter.prototype.totalCount = function(){
return this.count;
}
MyProject.js
function MyProject() {
this.iteration = 0;
}
MyProject.prototype.addIteration = function(iteration) {
this.iteration += iteration;
}
MyProject.prototype.calculate = function() {
var averageCount = Counter.prototype.totalCount();
return averageCount/this.iteration;
}
MyProject_spec.js
describe("MyProject", function() {
var project, iteration1, iteration2, iteration3;
beforeEach(function(){
project = new MyProject();
iteration1 = new Counter();
iteration1.startCount(10);
iteration2 = new Counter();
iteration2.startCount(20);
iteration3 = new Counter();
iteration3.startCount(10);
});
it("can calculate(the average number of counting completed) for a set of iterations", function(){
project.addIteration(iteration1);
expect(project.calculate()).toEqual(10);
});