diff --git a/docs/rules/use-angular-locators.md b/docs/rules/use-angular-locators.md index f459e69..ad5faf7 100644 --- a/docs/rules/use-angular-locators.md +++ b/docs/rules/use-angular-locators.md @@ -1,6 +1,6 @@ # Recommend using built-in Angular-specific locators -Warn about using attributes like `ng-model`, `ng-bind`, `ng-repeat` inside CSS selectors. Recommend built-in specific locators instead. +Warn about using attributes like `ng-model`, `ng-bind`, `ng-repeat` and `ng-options` inside CSS selectors. Recommend built-in specific locators instead. ## Rule details @@ -9,6 +9,7 @@ Here is a mapping between the relevant attribute and a recommended locator: * `ng-model`/`data-ng-model` -> `by.model()` * `ng-bind`/`data-ng-bind` -> `by.binding()` or `by.exactBinding()` * `ng-repeat`/`data-ng-repeat` -> `by.repeater()` or `by.exactRepeater()` + * `ng-options`/`data-ng-options` -> `by.options()` Any use of the following patterns are considered warnings: @@ -19,6 +20,8 @@ $("[ng-bind=test]"); $$("[data-ng-bind=test]"); element(by.id("test")).$('[ng-repeat="item in items"]'); element(by.id("test")).$$('[data-ng-repeat="item in items"]'); +$('[ng-options="item in items"]'); +$$('[data-ng-options="item in items"]'); ``` The following patterns are not warnings: @@ -29,4 +32,5 @@ element(by.binding("test")); element(by.exactBinding("test")); element.all(by.repeater("item in items")); element.all(by.exactRepeater("item in items")); +element.all(by.options("item in items")); ``` diff --git a/lib/rules/use-angular-locators.js b/lib/rules/use-angular-locators.js index 1c8d15a..dc40c6d 100644 --- a/lib/rules/use-angular-locators.js +++ b/lib/rules/use-angular-locators.js @@ -10,7 +10,8 @@ module.exports = function (context) { var attributeToLocatorMap = { 'ng-model': ['by.model()'], 'ng-bind': ['by.binding()', 'by.exactBinding()'], - 'ng-repeat': ['by.repeater()', 'by.exactRepeater()'] + 'ng-repeat': ['by.repeater()', 'by.exactRepeater()'], + 'ng-options': ['by.options()'] } return { diff --git a/test/rules/use-angular-locators.js b/test/rules/use-angular-locators.js index 9c3db98..94ed741 100644 --- a/test/rules/use-angular-locators.js +++ b/test/rules/use-angular-locators.js @@ -11,7 +11,8 @@ eslintTester.run('use-angular-locators', rule, { 'element(by.binding("test"));', 'element(by.exactBinding("test"));', 'element.all(by.repeater("item in items"));', - 'element.all(by.exactRepeater("item in items"));' + 'element.all(by.exactRepeater("item in items"));', + 'element.all(by.options("item in items"));' ], invalid: [ @@ -62,6 +63,22 @@ eslintTester.run('use-angular-locators', rule, { message: 'Unexpected "ng-repeat" attribute used inside a CSS selector. Use by.repeater() or by.exactRepeater() locator instead' } ] + }, + { + code: 'element(by.id("test")).$(\'[ng-options="item in items"]\');', + errors: [ + { + message: 'Unexpected "ng-options" attribute used inside a CSS selector. Use by.options() locator instead' + } + ] + }, + { + code: 'element(by.id("test")).$$(\'[data-ng-options="item in items"]\');', + errors: [ + { + message: 'Unexpected "ng-options" attribute used inside a CSS selector. Use by.options() locator instead' + } + ] } ] })