Skip to content

Commit

Permalink
Merge pull request #32 from elo7/hackday-deprecate-isEmpty
Browse files Browse the repository at this point in the history
[hackday-deprecate-isEmpty] Adiciona método isPresent e deixa o isEmpty deprecado
  • Loading branch information
tcelestino authored Nov 15, 2016
2 parents 3b80d5b + 7421eb9 commit a4a68c6
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 6 deletions.
11 changes: 8 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -453,16 +453,21 @@ define(['doc'], function(doc) {
});
```

#### isEmpty
`.isEmpty()`
#### ~~isEmpty~~

###### Description:

This method is deprecated. Use the method `isPresent()` instead.

#### isPresent

###### Description:
Verifies if the element exists on the DOM. Returns boolean.

###### Sample:
``` js
define(['doc'], function(doc) {
doc('artile#content').isEmpty(); //Return true/false if the element exist
doc('artile#content').isPresent(); //Return true/false if the element exist
});
```

Expand Down
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "doc-amd",
"version": "1.0.11-SNAPSHOT",
"version": "1.0.11",
"homepage": "https://github.com/elo7/doc-amd",
"description": "A small DOM manipulation library",
"main": "doc.js",
Expand Down
7 changes: 6 additions & 1 deletion doc.js
Original file line number Diff line number Diff line change
Expand Up @@ -330,8 +330,13 @@ define('doc', ['event'], function(event) {
return query(parents);
},

'isPresent' : function() {
return this.els !== undefined && this.els.length > 0;
},

/* Deprecated */
'isEmpty' : function() {
return this.els === undefined || !this.els.length;
return !this.isPresent();
},

'on' : function(eventName, command, named) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "js-unit-tests",
"version": "1.0.11-SNAPSHOT",
"version": "1.0.11",
"description": "Elo7 doc js unit tests",
"keywords": [
"JS",
Expand Down
13 changes: 13 additions & 0 deletions test/docTest.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,18 @@
assert.equal( $('body').selectedText(),$("#selected-text-test").first().innerHTML);
});

it('should return false if element is not present', function(){
var element = $('.this-element-should-not-exists');
assert.equal(typeof element, "object");
assert.equal(element.isPresent(), false);
});

it('should return true if element is present', function(){
assert.equal($('input').isPresent(), true);
assert.equal($('#form-test').isPresent(), true);
assert.equal($('.find').isPresent(), true);
});

it("should return object with isEmpty true when not find any element with given selector", function(){
var element = $("#this-element-should-not-exists");
assert.equal( typeof element,"object");
Expand Down Expand Up @@ -418,6 +430,7 @@
'previous',
'next',
'parent',
'isPresent',
'isEmpty',
'on',
'throttle',
Expand Down

0 comments on commit a4a68c6

Please sign in to comment.