Skip to content

Commit

Permalink
[deprecate] strings in definitions
Browse files Browse the repository at this point in the history
in order to unlock any strings to be considered as a scope(san650#408) in v2.
  • Loading branch information
ro0gr committed Mar 19, 2020
1 parent 8ce4718 commit 4c3568c
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 2 deletions.
11 changes: 10 additions & 1 deletion addon-test-support/create.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Ceibo from 'ceibo';
import { deprecate } from '@ember/application/deprecations';
import { render, setContext, removeContext } from './-private/context';
import { assign, getPageObjectDefinition, isPageObject, storePageObjectDefinition } from './-private/helpers';
import { visitable } from './properties/visitable';
Expand Down Expand Up @@ -63,7 +64,7 @@ function buildObject(node, blueprintKey, blueprint, defaultBuilder) {
definition = getPageObjectDefinition(blueprint);
} else {
Object.getOwnPropertyNames(blueprint).forEach((key) => {
const { get } = Object.getOwnPropertyDescriptor(blueprint, key);
const { get, value } = Object.getOwnPropertyDescriptor(blueprint, key);

if (typeof get === 'function') {
Object.defineProperty(blueprint, key, {
Expand All @@ -72,6 +73,14 @@ function buildObject(node, blueprintKey, blueprint, defaultBuilder) {
get
}
});
} else {
deprecate('do not use string values on definitions',
typeof value !== 'string' || ['scope', 'testContainer'].includes(key), {
id: 'ember-cli-page-object.string-properties-on-definition',
until: "2.0.0",
url: 'https://ember-cli-page-object.js.org/docs/v1.17.x/deprecations/#string-properties-on-definition',
}
)
}
});

Expand Down
39 changes: 38 additions & 1 deletion guides/deprecations.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,44 @@ title: Deprecations

This is a list of deprecations introduced in 1.x cycle:

## String properties on definition

**ID**: ember-cli-page-object.string-properties-on-definition

**Until**: 2.0.0

In v2 any strings inside definitions, other than `scope` and `testContainer`, would be treated as a `scope`.

Please make sure you don't have plain strings embedded into your definitions.

Bad:

```js
import { create } from 'ember-cli-page-object';

const page = create({
scope: 'input',

propertyName: 'I will become a nested component scope'
});
```

If you really need your definition to keep a string, use getter instead:

Good:

```js
import { create } from 'ember-cli-page-object';

const page = create({
scope: 'input',

get propertyName() {
return 'I will not become a scope :(';
}
});
```

## Multiple

**ID**: ember-cli-page-object.multiple
Expand Down Expand Up @@ -66,7 +104,6 @@ const page = create({
assert.deepEqual(page.tags, ['one', 'two', 'three'])
```


## Is property

**ID**: ember-cli-page-object.is-property
Expand Down
41 changes: 41 additions & 0 deletions tests/integration/deprecations/string-properties-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { module, test } from 'qunit';
import { create } from 'ember-cli-page-object';
import require from 'require';

if (require.has('@ember/test-helpers')) {
module('Deprecation | string-properties', function() {
test('works at top-level', function(assert) {
this.page = create({
stringProp: ''
});

assert.expectDeprecation()
});

test('works for nested definitions', function(assert) {
this.page = create({
nested: {
stringProp: ''
}
});

assert.expectDeprecation()
});

test('allows scope', function(assert) {
this.page = create({
scope: ''
});

assert.expectNoDeprecation()
});

test('allows testContainer', function(assert) {
this.page = create({
testContainer: ''
});

assert.expectNoDeprecation()
});
});
}

0 comments on commit 4c3568c

Please sign in to comment.