0

In the API Documentation there is a snippet:

casper.waitFor(function check() {
    return this.evaluate(function() {
        return document.querySelectorAll('ul.your-list li').length > 2;
    });
}, function then() {
    this.captureSelector('yoursitelist.png', 'ul.your-list');
}, function timeout() {
    this.echo("I can't haz my screenshot.").exit();
});

I need this, but in a coffeescript project. I tried to rewrite it into coffeescript but it didn’t work. Even if i let js2coffe do the job, i get some invalid coffeescript from valid javascript:

enter image description here

i dont know how to pass a list of named functions into another function correctly.

DerZyklop
  • 3,672
  • 2
  • 19
  • 27

1 Answers1

2

CoffeeScript doesn't really support named functions like that, see:

That specific example doesn't need them anyway, it looks like they're just there for documentation purposes so you could write:

check    = -> @evaluate(-> document.querySelectorAll('ul.your-list li').length > 2)
and_then = -> @captureSelector('yoursitelist.png', 'ul.your-list')
timeout  = -> @echo("I can't haz my screenshot.").exit()
casper.waitFor(check, and_then, timeout)

in CoffeeScript to get the same effect.

Community
  • 1
  • 1
mu is too short
  • 426,620
  • 70
  • 833
  • 800
  • 1
    They're there primarily for documentation purposes, but they will be printed in some cases when there is an error or when verbose logging is enabled. – Artjom B. Nov 25 '14 at 17:10
  • @ArtjomB. But like I said, CoffeeScript doesn't support them so you're out of luck unless you want to do unnatural things with backticks. If you have a problem with this then CoffeeScript isn't the right language for you. – mu is too short Nov 25 '14 at 17:20
  • @muistooshort sometimes you don’t choose coffeescript yourself. e.g. when you fix a bug in an existing coffeescript-app ;) but thats not the question here anyways.. your answer is correct. Thank you!! – DerZyklop Nov 26 '14 at 16:29