forked from cheeriojs/cheerio
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
From [the jQuery API docs on $.contain()](http://api.jquery.com/jQuery.contains/) > Description: Check to see if a DOM element is within another DOM element. > > jQuery.contains( container, contained ) > > - **container** The DOM element that may contain the other element. > - **contained** The DOM element that may be contained by the other element. > > **Note:** The first argument *must* be a DOM element, not a jQuery object or > plain JavaScript object. Add additional fixture to more thoroughly test the logic for nested structures. Add to project documentation.
- Loading branch information
1 parent
91a336a
commit 3e2d19e
Showing
4 changed files
with
65 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
var expect = require('expect.js'), | ||
$ = require('../'), | ||
food = require('./fixtures').food; | ||
|
||
describe('utility methods', function() { | ||
|
||
describe('.contains', function() { | ||
|
||
it('(container, contained) : should correctly detect the provided element', function() { | ||
var $food = $(food); | ||
var $fruits = $food.find('#fruits'); | ||
var $apple = $fruits.find('.apple'); | ||
|
||
expect($.contains($food[0], $fruits[0])).to.equal(true); | ||
expect($.contains($food[0], $apple[0])).to.equal(true); | ||
}); | ||
|
||
it('(container, other) : should not detect elements that are not contained', function() { | ||
var $food = $(food); | ||
var $fruits = $food.find('#fruits'); | ||
var $vegetables = $food.find('#vegetables'); | ||
var $apple = $fruits.find('.apple'); | ||
|
||
expect($.contains($vegetables[0], $apple[0])).to.equal(false); | ||
expect($.contains($fruits[0], $vegetables[0])).to.equal(false); | ||
expect($.contains($vegetables[0], $fruits[0])).to.equal(false); | ||
expect($.contains($fruits[0], $fruits[0])).to.equal(false); | ||
expect($.contains($vegetables[0], $vegetables[0])).to.equal(false); | ||
}); | ||
|
||
}); | ||
|
||
}); |