diff --git a/packages/ember-htmlbars/lib/utils/is-component.js b/packages/ember-htmlbars/lib/utils/is-component.js index 403a1ad341e..5aaf8deb442 100644 --- a/packages/ember-htmlbars/lib/utils/is-component.js +++ b/packages/ember-htmlbars/lib/utils/is-component.js @@ -3,6 +3,8 @@ @submodule ember-htmlbars */ +import { ISNT_HELPER_CACHE } from "ember-htmlbars/system/lookup-helper"; + /* Given a path name, returns whether or not a component with that name was found in the container. @@ -10,7 +12,7 @@ export default function isComponent(env, scope, path) { var container = env.container; if (!container) { return false; } - + if (ISNT_HELPER_CACHE.get(path)) { return false; } return container._registry.has('component:' + path) || container._registry.has('template:components/' + path); } diff --git a/packages/ember-htmlbars/tests/helpers/component_test.js b/packages/ember-htmlbars/tests/helpers/component_test.js index 93a9b6268e4..fd9364281b9 100644 --- a/packages/ember-htmlbars/tests/helpers/component_test.js +++ b/packages/ember-htmlbars/tests/helpers/component_test.js @@ -217,4 +217,19 @@ if (Ember.FEATURES.isEnabled('ember-htmlbars-component-helper')) { }); equal(view.$().text(), 'Max - Max|James - James|', 'component was updated and re-rendered'); }); + + QUnit.test('dashless components should not be found', function() { + expect(1); + + registry.register('template:components/dashless', compile('Do not render me!')); + + view = EmberView.extend({ + template: compile('{{component "dashless"}}'), + container: container + }).create(); + + expectAssertion(function() { + runAppend(view); + }, /You cannot use 'dashless' as a component name. Component names must contain a hyphen./); + }); } diff --git a/packages/ember-htmlbars/tests/integration/binding_integration_test.js b/packages/ember-htmlbars/tests/integration/binding_integration_test.js index 9f61290b4a4..0880c86b764 100644 --- a/packages/ember-htmlbars/tests/integration/binding_integration_test.js +++ b/packages/ember-htmlbars/tests/integration/binding_integration_test.js @@ -87,6 +87,16 @@ QUnit.test("should be able to update when bound property updates", function() { equal(view.$('i').text(), 'second, second - computed', "view rerenders when bound properties change"); }); +QUnit.test('should allow rendering of undefined props', function() { + view = EmberView.create({ + template: compile('{{name}}') + }); + + runAppend(view); + + equal(view.$().text(), '', 'rendered undefined binding'); +}); + QUnit.test('should cleanup bound properties on rerender', function() { view = EmberView.create({ controller: EmberObject.create({ name: 'wycats' }), diff --git a/packages/ember-htmlbars/tests/integration/component_invocation_test.js b/packages/ember-htmlbars/tests/integration/component_invocation_test.js index 665a3ef3f56..dd94fb6fae8 100644 --- a/packages/ember-htmlbars/tests/integration/component_invocation_test.js +++ b/packages/ember-htmlbars/tests/integration/component_invocation_test.js @@ -106,6 +106,43 @@ QUnit.test('non-block with properties on attrs and component class', function() equal(jQuery('#qunit-fixture').text(), 'In layout - someProp: something here'); }); +QUnit.test('lookup of component takes priority over property', function() { + expect(1); + + registry.register('template:components/some-component', compile('some-component')); + + view = EmberView.extend({ + template: compile('{{some-prop}} {{some-component}}'), + container: container, + context: { + 'some-component': 'not-some-component', + 'some-prop': 'some-prop' + } + }).create(); + + runAppend(view); + + equal(jQuery('#qunit-fixture').text(), 'some-prop some-component'); +}); + +QUnit.test('component without dash is not looked up', function() { + expect(1); + + registry.register('template:components/somecomponent', compile('somecomponent')); + + view = EmberView.extend({ + template: compile('{{somecomponent}}'), + container: container, + context: { + 'somecomponent': 'notsomecomponent' + } + }).create(); + + runAppend(view); + + equal(jQuery('#qunit-fixture').text(), 'notsomecomponent'); +}); + QUnit.test('rerendering component with attrs from parent', function() { var willUpdate = 0; var didReceiveAttrs = 0; diff --git a/packages/ember-htmlbars/tests/integration/component_lookup_test.js b/packages/ember-htmlbars/tests/integration/component_lookup_test.js deleted file mode 100644 index 833faca854e..00000000000 --- a/packages/ember-htmlbars/tests/integration/component_lookup_test.js +++ /dev/null @@ -1,40 +0,0 @@ -import EmberView from "ember-views/views/view"; -import Registry from "container/registry"; -import compile from "ember-template-compiler/system/compile"; -import ComponentLookup from 'ember-views/component_lookup'; -import { runAppend, runDestroy } from "ember-runtime/tests/utils"; - -var registry, container, view; - -QUnit.module('component - lookup', { - setup() { - registry = new Registry(); - container = registry.container(); - registry.optionsForType('component', { singleton: false }); - registry.optionsForType('view', { singleton: false }); - registry.optionsForType('template', { instantiate: false }); - registry.optionsForType('helper', { instantiate: false }); - registry.register('component-lookup:main', ComponentLookup); - }, - - teardown() { - runDestroy(container); - runDestroy(view); - registry = container = view = null; - } -}); - -QUnit.test('dashless components should not be found', function() { - expect(1); - - registry.register('template:components/dashless', compile('Do not render me!')); - - view = EmberView.extend({ - template: compile('{{dashless}}'), - container: container - }).create(); - - expectAssertion(function() { - runAppend(view); - }, /You cannot use 'dashless' as a component name. Component names must contain a hyphen./); -});