Skip to content

Commit

Permalink
Merge pull request #15940 from pizza/karim/non-empty-strings
Browse files Browse the repository at this point in the history
[BUGFIX beta] assert that `classNameBinding` items are non-empty strings
  • Loading branch information
rwjblue authored Dec 7, 2017
2 parents 323f790 + b41943e commit 1c1e7dc
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
4 changes: 2 additions & 2 deletions packages/ember-glimmer/lib/component-managers/curly.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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']() {
Expand Down

0 comments on commit 1c1e7dc

Please sign in to comment.