From b41943e2d8b6344646ed410fc342a0f441cd9f7a Mon Sep 17 00:00:00 2001 From: Karim Frenn Date: Thu, 7 Dec 2017 12:15:43 +0000 Subject: [PATCH] [BUGFIX beta] assert that `classNameBinding` items are non-empty strings --- .../lib/component-managers/curly.ts | 4 ++-- .../components/class-bindings-test.js | 18 ++++++++++++++++-- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/packages/ember-glimmer/lib/component-managers/curly.ts b/packages/ember-glimmer/lib/component-managers/curly.ts index 2cb0923340d..a8fe2f7266e 100644 --- a/packages/ember-glimmer/lib/component-managers/curly.ts +++ b/packages/ember-glimmer/lib/component-managers/curly.ts @@ -412,12 +412,12 @@ export function validatePositionalParameters(named: NamedArguments, positional: } export function processComponentInitializationAssertions(component: Component, props: any) { - assert(`classNameBindings must be strings: ${component}`, (() => { + assert(`classNameBindings must be non-empty strings: ${component}`, (() => { let { classNameBindings } = component; for (let i = 0; i < classNameBindings.length; i++) { let binding = classNameBindings[i]; - if (typeof binding !== 'string') { + if (typeof binding !== 'string' || binding.length === 0) { return false; } } diff --git a/packages/ember-glimmer/tests/integration/components/class-bindings-test.js b/packages/ember-glimmer/tests/integration/components/class-bindings-test.js index aba6094cf39..b7a0b16310e 100644 --- a/packages/ember-glimmer/tests/integration/components/class-bindings-test.js +++ b/packages/ember-glimmer/tests/integration/components/class-bindings-test.js @@ -297,14 +297,28 @@ moduleFor('ClassNameBindings integration', class extends RenderingTest { let FooBarComponent = Component.extend({ foo: 'foo', bar: 'bar', - classNameBindings: ['foo', ,'bar'] // eslint-disable-line no-sparse-arrays + classNameBindings: ['foo', , 'bar'] // eslint-disable-line no-sparse-arrays }); this.registerComponent('foo-bar', { ComponentClass: FooBarComponent, template: 'hello' }); expectAssertion(() => { this.render('{{foo-bar}}'); - }, /classNameBindings must be strings/); + }, /classNameBindings must be non-empty strings/); + } + + ['@test it asserts that items must be non-empty strings']() { + let FooBarComponent = Component.extend({ + foo: 'foo', + bar: 'bar', + classNameBindings: ['foo', '', 'bar'] + }); + + this.registerComponent('foo-bar', { ComponentClass: FooBarComponent, template: 'hello' }); + + expectAssertion(() => { + this.render('{{foo-bar}}'); + }, /classNameBindings must be non-empty strings/); } ['@test it can set class name bindings in the constructor']() {