Skip to content

Commit abdc442

Browse files
mixonicrwjblue
authored andcommitted
[CLEANUP beta] Assert on view and controller keywords
(cherry picked from commit 8f72bf2)
1 parent 75b2a74 commit abdc442

File tree

18 files changed

+306
-258
lines changed

18 files changed

+306
-258
lines changed
Lines changed: 44 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,72 +1,100 @@
1+
import Ember from 'ember-metal/core';
12
import EmberComponent from 'ember-views/views/component';
23
import { runAppend, runDestroy } from 'ember-runtime/tests/utils';
34
import compile from 'ember-template-compiler/system/compile';
45

56
import { registerAstPlugin, removeAstPlugin } from 'ember-htmlbars/tests/utils';
67
import TransformEachIntoCollection from 'ember-template-compiler/plugins/transform-each-into-collection';
7-
import DeprecateViewAndControllerPaths from 'ember-template-compiler/plugins/deprecate-view-and-controller-paths';
8+
import AssertNoViewAndControllerPaths from 'ember-template-compiler/plugins/assert-no-view-and-controller-paths';
89

910
let component;
1011

1112
QUnit.module('ember-htmlbars: compat - controller keyword (use as a path)', {
13+
setup() {
14+
Ember.ENV._ENABLE_LEGACY_CONTROLLER_SUPPORT = false;
15+
registerAstPlugin(AssertNoViewAndControllerPaths);
16+
17+
component = null;
18+
},
19+
teardown() {
20+
runDestroy(component);
21+
22+
removeAstPlugin(AssertNoViewAndControllerPaths);
23+
Ember.ENV._ENABLE_LEGACY_CONTROLLER_SUPPORT = true;
24+
}
25+
});
26+
27+
QUnit.test('reading the controller keyword fails assertion', function() {
28+
var text = 'a-prop';
29+
expectAssertion(function() {
30+
component = EmberComponent.extend({
31+
prop: text,
32+
layout: compile('{{controller.prop}}')
33+
}).create();
34+
35+
runAppend(component);
36+
}, /Using `{{controller}}` or any path based on it .*/);
37+
});
38+
39+
QUnit.module('ember-htmlbars: compat - controller keyword (use as a path) [LEGACY]', {
1240
setup() {
1341
registerAstPlugin(TransformEachIntoCollection);
14-
registerAstPlugin(DeprecateViewAndControllerPaths);
1542

1643
component = null;
1744
},
1845
teardown() {
1946
runDestroy(component);
2047

2148
removeAstPlugin(TransformEachIntoCollection);
22-
removeAstPlugin(DeprecateViewAndControllerPaths);
2349
}
2450
});
2551

26-
QUnit.test('reading the controller keyword is deprecated [DEPRECATED]', function() {
52+
QUnit.test('reading the controller keyword works [LEGACY]', function() {
2753
var text = 'a-prop';
28-
expectDeprecation(function() {
54+
ignoreAssertion(function() {
2955
component = EmberComponent.extend({
3056
prop: text,
3157
layout: compile('{{controller.prop}}')
3258
}).create();
59+
}, /Using `{{controller}}` or any path based on it .*/);
3360

34-
runAppend(component);
35-
}, /Using `{{controller}}` or any path based on it .* has been deprecated./);
61+
runAppend(component);
3662
equal(component.$().text(), text, 'controller keyword is read');
3763
});
3864

39-
QUnit.test('reading the controller keyword for hash is deprecated [DEPRECATED]', function() {
40-
expectDeprecation(function() {
65+
QUnit.test('reading the controller keyword for hash [LEGACY]', function() {
66+
ignoreAssertion(function() {
4167
component = EmberComponent.extend({
4268
prop: true,
4369
layout: compile('{{if true \'hiho\' option=controller.prop}}')
4470
}).create();
4571

4672
runAppend(component);
47-
}, /Using `{{controller}}` or any path based on it .* has been deprecated./);
73+
}, /Using `{{controller}}` or any path based on it .*/);
74+
ok(true, 'access keyword');
4875
});
4976

50-
QUnit.test('reading the controller keyword for param is deprecated [DEPRECATED]', function() {
77+
QUnit.test('reading the controller keyword for param [LEGACY]', function() {
5178
var text = 'a-prop';
52-
expectDeprecation(function() {
79+
ignoreAssertion(function() {
5380
component = EmberComponent.extend({
5481
prop: true,
5582
layout: compile(`{{if controller.prop '${text}'}}`)
5683
}).create();
5784

5885
runAppend(component);
59-
}, /Using `{{controller}}` or any path based on it .* has been deprecated./);
86+
}, /Using `{{controller}}` or any path based on it .*/);
6087
equal(component.$().text(), text, 'controller keyword is read');
6188
});
6289

63-
QUnit.test('reading the controller keyword for param with block is deprecated [DEPRECATED]', function() {
64-
expectDeprecation(function() {
90+
QUnit.test('reading the controller keyword for param with block fails assertion [LEGACY]', function() {
91+
ignoreAssertion(function() {
6592
component = EmberComponent.extend({
6693
prop: true,
6794
layout: compile(`{{#each controller as |things|}}{{/each}}`)
6895
}).create();
6996

7097
runAppend(component);
71-
}, /Using `{{controller}}` or any path based on it .* has been deprecated./);
98+
}, /Using `{{controller}}` or any path based on it .*/);
99+
ok(true, 'access keyword');
72100
});

packages/ember-htmlbars/tests/compat/view_helper_test.js

Lines changed: 47 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import Ember from 'ember-metal/core';
12
import EmberComponent from 'ember-views/views/component';
23
import EmberView from 'ember-views/views/view';
34
import EmberSelectView from 'ember-views/views/select';
@@ -6,7 +7,7 @@ import compile from 'ember-template-compiler/system/compile';
67
import Registry from 'container/registry';
78

89
import { registerAstPlugin, removeAstPlugin } from 'ember-htmlbars/tests/utils';
9-
import DeprecateViewHelper from 'ember-template-compiler/plugins/deprecate-view-helper';
10+
import AssertNoViewHelper from 'ember-template-compiler/plugins/assert-no-view-helper';
1011

1112
import { registerKeyword, resetKeyword } from 'ember-htmlbars/tests/utils';
1213
import viewKeyword from 'ember-htmlbars/keywords/view';
@@ -15,7 +16,8 @@ let component, registry, container, originalViewKeyword;
1516

1617
QUnit.module('ember-htmlbars: compat - view helper', {
1718
setup() {
18-
registerAstPlugin(DeprecateViewHelper);
19+
Ember.ENV._ENABLE_LEGACY_VIEW_SUPPORT = false;
20+
registerAstPlugin(AssertNoViewHelper);
1921

2022
originalViewKeyword = registerKeyword('view', viewKeyword);
2123

@@ -25,61 +27,93 @@ QUnit.module('ember-htmlbars: compat - view helper', {
2527
teardown() {
2628
runDestroy(component);
2729
runDestroy(container);
28-
removeAstPlugin(DeprecateViewHelper);
30+
removeAstPlugin(AssertNoViewHelper);
31+
Ember.ENV._ENABLE_LEGACY_VIEW_SUPPORT = true;
2932
registry = container = component = null;
3033

3134
resetKeyword('view', originalViewKeyword);
3235
}
3336
});
3437

35-
QUnit.test('using the view helper with a string (inline form) is deprecated [DEPRECATED]', function(assert) {
38+
QUnit.test('using the view helper fails assertion', function(assert) {
3639
const ViewClass = EmberView.extend({
3740
template: compile('fooView')
3841
});
3942
registry.register('view:foo', ViewClass);
4043

41-
expectDeprecation(function() {
44+
expectAssertion(function() {
4245
component = EmberComponent.extend({
4346
layout: compile('{{view \'foo\'}}'),
4447
container
4548
}).create();
4649

4750
runAppend(component);
48-
}, /Using the `{{view "string"}}` helper is deprecated/);
51+
}, /Using the `{{view "string"}}` helper/);
52+
});
53+
54+
QUnit.module('ember-htmlbars: compat - view helper [LEGACY]', {
55+
setup() {
56+
originalViewKeyword = registerKeyword('view', viewKeyword);
57+
58+
registry = new Registry();
59+
container = registry.container();
60+
},
61+
teardown() {
62+
runDestroy(component);
63+
runDestroy(container);
64+
registry = container = component = null;
65+
66+
resetKeyword('view', originalViewKeyword);
67+
}
68+
});
69+
70+
QUnit.test('using the view helper with a string (inline form) fails assertion [LEGACY]', function(assert) {
71+
const ViewClass = EmberView.extend({
72+
template: compile('fooView')
73+
});
74+
registry.register('view:foo', ViewClass);
75+
76+
ignoreAssertion(function() {
77+
component = EmberComponent.extend({
78+
layout: compile('{{view \'foo\'}}'),
79+
container
80+
}).create();
81+
82+
runAppend(component);
83+
});
4984

5085
assert.equal(component.$().text(), 'fooView', 'view helper is still rendered');
5186
});
5287

53-
QUnit.test('using the view helper with a string (block form) is deprecated [DEPRECATED]', function(assert) {
88+
QUnit.test('using the view helper with a string (block form) fails assertion [LEGACY]', function(assert) {
5489
const ViewClass = EmberView.extend({
5590
template: compile('Foo says: {{yield}}')
5691
});
5792
registry.register('view:foo', ViewClass);
5893

59-
expectDeprecation(function() {
94+
ignoreAssertion(function() {
6095
component = EmberComponent.extend({
6196
layout: compile('{{#view \'foo\'}}I am foo{{/view}}'),
6297
container
6398
}).create();
6499

65100
runAppend(component);
66-
}, /Using the `{{view "string"}}` helper is deprecated/);
101+
});
67102

68103
assert.equal(component.$().text(), 'Foo says: I am foo', 'view helper is still rendered');
69104
});
70105

71-
QUnit.test('using the view helper with string "select" has its own deprecation message [DEPRECATED]', function(assert) {
106+
QUnit.test('using the view helper with string "select" fails assertion [LEGACY]', function(assert) {
72107
registry.register('view:select', EmberSelectView);
73108

74-
expectDeprecation(function() {
109+
ignoreAssertion(function() {
75110
component = EmberComponent.extend({
76111
layout: compile('{{view \'select\'}}'),
77112
container
78113
}).create();
79114

80115
runAppend(component);
81-
}, /Using `{{view "select"}}` is deprecated/);
116+
});
82117

83118
assert.ok(!!component.$('select').length, 'still renders select');
84119
});
85-
Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,35 @@
1+
import Ember from 'ember-metal/core';
12
import EmberComponent from 'ember-views/views/component';
23
import { runAppend, runDestroy } from 'ember-runtime/tests/utils';
34
import compile from 'ember-template-compiler/system/compile';
45

56
import { registerAstPlugin, removeAstPlugin } from 'ember-htmlbars/tests/utils';
6-
import DeprecateViewAndControllerPaths from 'ember-template-compiler/plugins/deprecate-view-and-controller-paths';
7+
import AssertNoViewAndControllerPaths from 'ember-template-compiler/plugins/assert-no-view-and-controller-paths';
78

89
let component;
910

1011
QUnit.module('ember-htmlbars: compat - view keyword (use as a path)', {
1112
setup() {
12-
registerAstPlugin(DeprecateViewAndControllerPaths);
13+
Ember.ENV._ENABLE_LEGACY_VIEW_SUPPORT = false;
14+
registerAstPlugin(AssertNoViewAndControllerPaths);
1315
component = null;
1416
},
1517
teardown() {
1618
runDestroy(component);
17-
removeAstPlugin(DeprecateViewAndControllerPaths);
19+
removeAstPlugin(AssertNoViewAndControllerPaths);
20+
Ember.ENV._ENABLE_LEGACY_VIEW_SUPPORT = true;
1821
}
1922
});
2023

21-
QUnit.test('reading the view keyword is deprecated [DEPRECATED]', function() {
24+
QUnit.test('reading the view keyword fails assertion', function() {
2225
var text = 'a-prop';
23-
expectDeprecation(function() {
26+
expectAssertion(function() {
2427
component = EmberComponent.extend({
2528
prop: text,
2629
layout: compile('{{view.prop}}')
2730
}).create();
2831

2932
runAppend(component);
30-
}, /Using `{{view}}` or any path based on it .* has been deprecated./);
31-
32-
equal(component.$().text(), text, 'view keyword is read');
33+
}, /Using `{{view}}` or any path based on it .*/);
3334
});
3435

packages/ember-htmlbars/tests/helpers/collection_test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ QUnit.test('empty views should be removed when content is added to the collectio
186186
});
187187

188188
view = EmberView.create({
189+
_viewRegistry: {},
189190
listView: ListView,
190191
listController: listController,
191192
template: compile('{{#collection view.listView content=view.listController tagName="table"}} <td>{{view.content.title}}</td> {{/collection}}')

0 commit comments

Comments
 (0)