我正在寫一個程序來測試不同的三角形類型,我卡住了。這是我對我的測試:茉莉花Tdd第一次嘗試
(留下評論思考過程)。
APP-spec.js
describe("Answer", function() {
var equilateral;
var sideA;
var sideB;
var sideC;
it("Should return equilateral when all sides are equal", function() {
expect(whichTriangle(sideA, sideB, sideC).toEqual(sideA, sideB, sideC));
// expect (sideA).tobe(sideB);
// expect (sideB).tobe(sideC);
// expect (sideC).tobe(sideA);
// !expect (sideA, sideB, sideC).tobe(undefined);
});
it("Should return isosceles when 2 sides are equal", function() {
// let sideD: number;
// let sideE: number;
// let sideF: number;
expect(sideA).tobe((sideB));
expect(sideB).tobe((sideC));
!expect(sideA, sideB, sideC).toEqual(sideA, sideB, sideC);
});
it("Should return scalene when no sides are equal", function() {
// let sideG: number;
// let sideH: number;
// let sideI: number;
!expect(sideA).tobe(sideB);
!expect(sideB).tobe(sideC);
!expect(sideC).tobe(sideA);
});
});
describe("Isosceles triangle", function() {
var isosceles;
});
這是我有我的app.js文件:
app.js
function whichTriangle(sideA, sideB, sideC) {
// let side1 = document.getElementById('sideA').value();
// let side2 = document.getElementById('sideB').value();
// let side3 = document.getElementById('sideC').value();
if (side1 === side2 && side3) {
console.log("triangle is Equilateral");
}
else if (side1 === side2 && side1 != side3) {
console.log("triangle is an isosceles");
}
else if (side1 != side2 && side1 != side3 && side2 != side3) {
console.log('triangle is a scalene');
}
else if (side1 === null || side1 === undefined ||
side2 === null || side2 === undefined ||
side3 === null || side3 === undefined) {
console.log('You must enter a number for all 3 sides');
}
else {
console.log('You got me I don\'t know what this shape is. Maybe a rectangle?');
}
}
equalSides(1, 1, 1);
這是我收到的時候我運行應用程序:
Jasmine Spec Runner
3 specs, 3 failures
Spec List | Failures
Answer Should return equilateral when all sides are equal
TypeError: Cannot read property 'value' of null
TypeError: Cannot read property 'value' of null
at equalSides (http://localhost:63342/greater%20sum%20test/src/app.js:2:49)
at Object.<anonymous> (http://localhost:63342/greater%20sum%20test/spec/app-spec.js:7:16)
at attemptSync (http://localhost:63342/greater%20sum%20test/lib/jasmine-2.6.4/jasmine.js:3898:24)
at QueueRunner.run (http://localhost:63342/greater%20sum%20test/lib/jasmine-2.6.4/jasmine.js:3887:9)
at QueueRunner.execute (http://localhost:63342/greater%20sum%20test/lib/jasmine-2.6.4/jasmine.js:3872:10)
at Spec.queueRunnerFactory (http://localhost:63342/greater%20sum%20test/lib/jasmine-2.6.4/jasmine.js:816:35)
at Spec.execute (http://localhost:63342/greater%20sum%20test/lib/jasmine-2.6.4/jasmine.js:473:10)
at Object.fn (http://localhost:63342/greater%20sum%20test/lib/jasmine-2.6.4/jasmine.js:4975:37)
at attemptAsync (http://localhost:63342/greater%20sum%20test/lib/jasmine-2.6.4/jasmine.js:3945:24)
at QueueRunner.run (http://localhost:63342/greater%20sum%20test/lib/jasmine-2.6.4/jasmine.js:3884:9)
Answer Should return isosceles when 2 sides are equal
TypeError: expect(...).tobe is not a function
TypeError: expect(...).tobe is not a function
at Object.<anonymous> (http://localhost:63342/greater%20sum%20test/spec/app-spec.js:17:23)
at attemptSync (http://localhost:63342/greater%20sum%20test/lib/jasmine-2.6.4/jasmine.js:3898:24)
at QueueRunner.run (http://localhost:63342/greater%20sum%20test/lib/jasmine-2.6.4/jasmine.js:3887:9)
at QueueRunner.execute (http://localhost:63342/greater%20sum%20test/lib/jasmine-2.6.4/jasmine.js:3872:10)
at Spec.queueRunnerFactory (http://localhost:63342/greater%20sum%20test/lib/jasmine-2.6.4/jasmine.js:816:35)
at Spec.execute (http://localhost:63342/greater%20sum%20test/lib/jasmine-2.6.4/jasmine.js:473:10)
at Object.fn (http://localhost:63342/greater%20sum%20test/lib/jasmine-2.6.4/jasmine.js:4975:37)
at attemptAsync (http://localhost:63342/greater%20sum%20test/lib/jasmine-2.6.4/jasmine.js:3945:24)
at QueueRunner.run (http://localhost:63342/greater%20sum%20test/lib/jasmine-2.6.4/jasmine.js:3884:9)
at http://localhost:63342/greater%20sum%20test/lib/jasmine-2.6.4/jasmine.js:3924:18
Answer Should return scalene when no sides are equal
TypeError: expect(...).tobe is not a function
TypeError: expect(...).tobe is not a function
at Object.<anonymous> (http://localhost:63342/greater%20sum%20test/spec/app-spec.js:25:24)
at attemptSync (http://localhost:63342/greater%20sum%20test/lib/jasmine-2.6.4/jasmine.js:3898:24)
at QueueRunner.run (http://localhost:63342/greater%20sum%20test/lib/jasmine-2.6.4/jasmine.js:3887:9)
at QueueRunner.execute (http://localhost:63342/greater%20sum%20test/lib/jasmine-2.6.4/jasmine.js:3872:10)
at Spec.queueRunnerFactory (http://localhost:63342/greater%20sum%20test/lib/jasmine-2.6.4/jasmine.js:816:35)
at Spec.execute (http://localhost:63342/greater%20sum%20test/lib/jasmine-2.6.4/jasmine.js:473:10)
at Object.fn (http://localhost:63342/greater%20sum%20test/lib/jasmine-2.6.4/jasmine.js:4975:37)
at attemptAsync (http://localhost:63342/greater%20sum%20test/lib/jasmine-2.6.4/jasmine.js:3945:24)
at QueueRunner.run (http://localhost:63342/greater%20sum%20test/lib/jasmine-2.6.4/jasmine.js:3884:9)
at http://localhost:63342/greater%20sum%20test/lib/jasmine-2.6.4/jasmine.js:3924:18
當然,我知道我做錯了什麼,但任何在正確的方向微調是非常讚賞和批評是值得歡迎的。
太謝謝你了。我正在使用!其原因是我的IDE(webStorm)將其改爲!當我輸入_.not.toBe_,所以我想也許這是我不知道的新東西,並將其留下。我會做出改變並繼續努力。再次感謝你。 –
@PerryCraft,我加了一些'not'的例子 – MinusFour
哇,這很好,寫得很好,非常感謝你。可能是我回歸的最好的解釋答案。謝謝 –