Why in Jasmine, we cannot put the expect in an outside function?

inslain

New Member
If using Jasmine 1.3.1, I use\[code\]describe("TryTry", function() { var i; function checkForSituation(a) { // say, if this is made into a function because // there are a lot of processing console.log("THERE", a); expect(foo(3, a)).toEqual( 3 + a ); } for (i = 0; i < 5; i++) { console.log("HERE", i); it("should add for " + i, function() { checkForSituation(i); }); }});\[/code\]and foo is just:\[code\]function foo(a, b) { return a + b;}\[/code\]I would expect it to check for 0 to 4, and print out\[code\]HERE 0THERE 0HERE 1THERE 1 ...\[/code\]but instead, it just print in Chrome's console as: \[code\]HERE 0, HERE 1, ...\[/code\] and then \[code\]THERE 5\[/code\] five times. Does somebody know why an \[code\]expect\[/code\] cannot be put in an outside function like that and what to do in Jasmine if I need to put many steps into a function?As a side note, sometimes in JavaScript, I feel like a whole new language is developed and what you can usually do won't work -- and wonder what can be done to prevent this type of things from happening, something without knowing that it would happen.If you'd like to try it out, it is on https://github.com/jianlin/jasmine-looping-an-it-calling-function-that-does-expect
 
Top