Protractor tests in CoffeeScript produce "SyntaxError: unexpected"?

I am trying to write the following Protractor in CoffeeScript:

describe "tests", ->

  browser.get "/"

  it "should display Login page", ->
    expect(element(by.css("h1")).getText()).toBe "Login"

However, CoffeeScript spits out this error:

SyntaxError: unexpectedly

Solutions?

+4
source share
2 answers

As @meagar said it was reserved, you can use it in your protractor configuration in a block onPrepare:

require('coffee-script/register');

exports.config = {
  ....

  // by is reserved in coffee script
  onPrepare: function() {
    global.By = global.by;
  }
}

then

expect(element(By.css("h1")).getText()).toBe "Login"
+12
source

by is a reserved word in CoffeeScript used to indicate a loop step:

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

Use a different variable name.

+3
source

Source: https://habr.com/ru/post/1543677/


All Articles