Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Protractor tests in CoffeeScript producing "SyntaxError: unexpected by"?

I am trying to write the following Protractor test 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: unexpected by

Solutions?

like image 747
XåpplI'-I0llwlg'I - Avatar asked Dec 07 '22 01:12

XåpplI'-I0llwlg'I -


1 Answers

Like @meagar said it is reserved, you can alias it in your protractor config in the onPrepare block:

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"
like image 126
house9 Avatar answered Dec 08 '22 15:12

house9