for loop

58 views
Skip to first unread message

Edmond Wee

unread,
Feb 20, 2016, 7:44:36 PM2/20/16
to Jasmine
I have come across tutorials and explanation on for loop in jasmine. I still have a problem.

The pseudocode:

  1. navigate to site
  2. click on dropdown
  3. get count of items in dropdown
  4. save the count
  5. use that count in for loop
I can get the count and save it but the for loop does not execute.


a short snippet:

function search_options(input){
it('check drop down items', function(){

console.log('input'+input);

},delay);
}


for(var x = 1;x <= cnt; x++){//click item #1
search_options(cnt);

}

The problem is that the for loop does not execute.

It would be really great if I could get some guidance on this.

Gregg Van Hove

unread,
Feb 23, 2016, 2:26:57 PM2/23/16
to jasmi...@googlegroups.com
In the example you have here, the `for` loop will run when that spec file is originally included/parsed/required/etc, so in order for the loop to have anything to loop through your `cnt` variable will need to already have a value. You won't be able to populate that variable with a value as part of a `beforeEach` because that won't get executed until Jasmine executes the suite.

Hope this helps. Thanks for using Jasmine!

-Gregg

--
You received this message because you are subscribed to the Google Groups "Jasmine" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jasmine-js+...@googlegroups.com.
To post to this group, send email to jasmi...@googlegroups.com.
Visit this group at https://groups.google.com/group/jasmine-js.
For more options, visit https://groups.google.com/d/optout.

Kanu Kalra

unread,
Mar 27, 2016, 7:43:54 PM3/27/16
to Jasmine
Gregg,

I am not sure if I understand your answer. I am facing the same issue. Which one do you recommend?
1. Is it not possible to do a for loop around jasmine specs or 'it' blocks?
2. It is possible, but the process shows in above email is not quite the right way.

If 2), could you please post a snippet that works.

Thanks,
Kanu
Reply all
Reply to author
Forward
0 new messages