Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[deprecate] strings in definitions #485

Merged
merged 2 commits into from
Mar 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 string values in definitions, other than `scope` and `testContainer`, would be treated as a `scope` selectors.

Please make sure there are no plain strings used in 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()
});
});
}