1 | 'use strict';
|
2 |
|
3 | var isEmpty = require('../src/empty'),
|
4 | assert = require('chai').assert;
|
5 |
|
6 |
|
7 | describe('empty', function() {
|
8 |
|
9 | var supportsNonEnumerableProperties = (function() {
|
10 | var o = {};
|
11 | Object.defineProperty(o, 'test', {
|
12 | enumerable: false,
|
13 | value: 10
|
14 | });
|
15 |
|
16 | return Object.getOwnPropertyDescriptor(o, 'test').enumerable === false;
|
17 | })();
|
18 |
|
19 | it('checks if object has no enumerable properties', function() {
|
20 | var objectWithoutEnumerableProperties = {};
|
21 |
|
22 | Object.defineProperty(objectWithoutEnumerableProperties, 'property', {
|
23 | enumerable: false,
|
24 | value: 'yo'
|
25 | });
|
26 |
|
27 | if (supportsNonEnumerableProperties) {
|
28 | assert.ok(isEmpty(objectWithoutEnumerableProperties));
|
29 | }
|
30 |
|
31 | assert.ok(isEmpty({}));
|
32 | assert.ok(!isEmpty({some: 'property'}));
|
33 | });
|
34 |
|
35 | it('checks if object is an empty array like object', function() {
|
36 | assert.ok(isEmpty(arguments));
|
37 | assert.ok(isEmpty({length: 0}));
|
38 | assert.ok(isEmpty([]));
|
39 | });
|
40 |
|
41 | it('checks if object is an empty string', function() {
|
42 | assert.ok(isEmpty(''));
|
43 | assert.ok(new String(''));
|
44 |
|
45 | assert.ok(!isEmpty(new String(' ')));
|
46 | assert.ok(!isEmpty(' '));
|
47 | assert.ok(!isEmpty('test'));
|
48 | });
|
49 |
|
50 | it('every other value is not empty', function() {
|
51 | assert.ok(!isEmpty(0));
|
52 | assert.ok(!isEmpty(false));
|
53 | });
|
54 | });
|