Question

I'm playing around with Coffeescript, trying to convert a JavaScript file to Coffeescript. This is valid JavaScript:

element(by.model('query.address')).sendKeys('947');

This is invalid Coffeescript:

element(by.model('query.address')).sendKeys('947')

What is invalid about the Coffeescript? Coffeelint says "unexpected BY".

Was it helpful?

Solution

CoffeeScript uses the by keyword to let you use a specific step when looping through a range.

From the documentation:

To step through a range comprehension in fixed-size chunks, use by, for example:

evens = (x for x in [0..10] by 2)

Since JavaScript doesn't use by it's valid. For CoffeeScript, try renaming the by to something else.

In response to the comment, since Protractor provides its own by global variable, one idea is to alias it via CoffeeScript's embedded JavaScript syntax (code surrounded by back-ticks), then continue using CoffeeScript and the alias throughout your code.

You'll need to test this type of code:

ptorBy = `by`
element(ptorBy.model('query.address')).sendKeys('947')

Where ptor is just my short-hand for "Protractor." This translates to the following JavaScript:

var ptorBy;
ptorBy = by;
element(ptorBy.model('query.address')).sendKeys('947');
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top