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

[BUGFIX] isEmpty on nested objects #16879

Merged
merged 1 commit into from Feb 11, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 4 additions & 6 deletions packages/@ember/-internals/metal/lib/is_empty.ts
Expand Up @@ -52,18 +52,16 @@ export default function isEmpty(obj: any): boolean {
if (typeof size === 'number') {
return !size;
}
}

if (typeof obj.length === 'number' && objectType !== 'function') {
return !obj.length;
}

if (objectType === 'object') {
let length = get(obj, 'length');
if (typeof length === 'number') {
return !length;
}
}

if (typeof obj.length === 'number' && objectType !== 'function') {
return !obj.length;
}

return false;
}
14 changes: 13 additions & 1 deletion packages/@ember/-internals/runtime/tests/core/is_empty_test.js
@@ -1,15 +1,27 @@
import { isEmpty } from '@ember/-internals/metal';
import ArrayProxy from '../../lib/system/array_proxy';
import ObjectProxy from '../../lib/system/object_proxy';
import { A as emberA } from '../../lib/mixins/array';
import { moduleFor, AbstractTestCase } from 'internal-test-helpers';

moduleFor(
'Ember.isEmpty',
class extends AbstractTestCase {
['@test Ember.isEmpty'](assert) {
['@test Ember.isEmpty ArrayProxy'](assert) {
let arrayProxy = ArrayProxy.create({ content: emberA() });

assert.equal(true, isEmpty(arrayProxy), 'for an ArrayProxy that has empty content');
}

['@test Ember.isEmpty ObjectProxy ArrayProxy'](assert) {
let arrayProxy = ArrayProxy.create({ content: emberA([]) });
let objectProxy = ObjectProxy.create({ content: arrayProxy });

assert.equal(
true,
isEmpty(objectProxy),
'for an ArrayProxy inside ObjectProxy that has empty content'
);
}
}
);