Skip to content

Commit

Permalink
Merge branch 'main' into test/lint
Browse files Browse the repository at this point in the history
  • Loading branch information
fb55 committed Jan 4, 2021
2 parents 613b681 + b6d3840 commit 09cde82
Show file tree
Hide file tree
Showing 15 changed files with 115 additions and 82 deletions.
7 changes: 7 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@
"allowImplicit": true
}
],
"eqeqeq": [
"error",
"always",
{
"null": "ignore"
}
],
"no-lonely-if": 2,
"no-proto": 2,
"curly": [2, "multi-line"],
Expand Down
3 changes: 3 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
# Enforce Unix newlines
* text=auto eol=lf

benchmark/documents/* binary
benchmark/jquery*.js binary
2 changes: 0 additions & 2 deletions benchmark/.gitattributes

This file was deleted.

4 changes: 2 additions & 2 deletions lib/api/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -383,10 +383,10 @@ exports.val = function (value) {
var option = this.find('option:selected');
if (!option) return;
if (!querying) {
if (this.attr('multiple') == null && typeof value == 'object') {
if (this.attr('multiple') == null && typeof value === 'object') {
return this;
}
if (typeof value != 'object') {
if (typeof value !== 'object') {
value = [value];
}
this.find('option').removeAttr('selected');
Expand Down
4 changes: 2 additions & 2 deletions lib/api/css.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ exports.css = function (prop, val) {
* @param {number} [idx] - Optional index within the selection.
*/
function setCss(el, prop, val, idx) {
if (typeof prop == 'string') {
if (typeof prop === 'string') {
var styles = getCss(el);
if (typeof val === 'function') {
val = val.call(el, idx, styles[prop]);
Expand All @@ -51,7 +51,7 @@ function setCss(el, prop, val, idx) {
}

el.attribs.style = stringify(styles);
} else if (typeof prop == 'object') {
} else if (typeof prop === 'object') {
Object.keys(prop).forEach(function (k) {
setCss(el, k, prop[k]);
});
Expand Down
6 changes: 1 addition & 5 deletions lib/api/manipulation.js
Original file line number Diff line number Diff line change
Expand Up @@ -413,11 +413,7 @@ exports.wrapAll = function (wrapper) {
wrapper = wrapper.call(this[0]);
}

var wrap = this._make(wrapper);

if (this[0].parent) {
wrap = wrap.insertBefore(this[0]);
}
var wrap = this._make(wrapper).insertBefore(this[0]);

// if html is given as wrapper, wrap may contain text elements
var elInsertLocation = { children: wrap };
Expand Down
52 changes: 39 additions & 13 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@
"parse5-htmlparser2-tree-adapter": "^6.0.1"
},
"devDependencies": {
"@types/node": "^14.14.16",
"@types/node": "^14.14.19",
"benchmark": "^2.1.4",
"eslint": "^7.16.0",
"eslint": "^7.17.0",
"eslint-config-prettier": "^7.1.0",
"eslint-plugin-jest": "^24.1.3",
"eslint-plugin-jsdoc": "^30.7.9",
"eslint-plugin-jsdoc": "^30.7.13",
"eslint-plugin-node": "^11.1.0",
"husky": "^4.3.6",
"jest": "^26.6.3",
Expand Down
30 changes: 0 additions & 30 deletions scripts/generate_history.sh

This file was deleted.

23 changes: 0 additions & 23 deletions scripts/prepublish

This file was deleted.

2 changes: 1 addition & 1 deletion test/__fixtures__/fixtures.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ exports.divcontainers = [
'<div class="inner">Fourth</div>',
'</div>',
'<div id="new"><div>',
'<div><p><em><b></b></em></p></div>',
'<div>\n\n<p><em><b></b></em></p>\n\n</div>',
'</div>',
].join('');

Expand Down
38 changes: 37 additions & 1 deletion test/api/manipulation.js
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,12 @@ describe('$(...)', function () {
expect($container[0].children[0]).toBe($wrap[0]);
});

it('(html) : should wrap elements with it', function () {
var parent = doc('<p>').wrapAll('<div></div>').parent();
expect(parent).toHaveLength(1);
expect(parent.is('div')).toBe(true);
});

it('(selector) : should find element from dom, wrap elements with it', function () {
$inner.wrapAll('#new');
var $container = doc('.container');
Expand All @@ -387,6 +393,36 @@ describe('$(...)', function () {
expect($new[0].parent).toBe($container[0]);
expect($container[0].children[0]).toBe($new[0]);
});

it('(function) : check execution', function () {
var $container = doc('.container');
var p = $container[0].parent;

var result = $container.wrapAll(function () {
return "<div class='red'><div class='tmp'></div></div>";
});

expect(result.parent()).toHaveLength(1);
expect($container.eq(0).parent().parent().is('.red')).toBe(true);
expect($container.eq(1).parent().parent().is('.red')).toBe(true);
expect($container.eq(0).parent().parent().parent().is(p)).toBe(true);
});

it('(function) : check execution characteristics', function () {
var $new = doc('#new');
var i = 0;

doc('no-result').wrapAll(function () {
i++;
return '';
});
expect(i).toBeFalsy();

$new.wrapAll(function (index) {
expect(this).toBe($new[0]);
expect(index).toBe(undefined);
});
});
});

describe('.append', function () {
Expand Down Expand Up @@ -797,7 +833,7 @@ describe('$(...)', function () {

describe('.after', function () {
it('() : should do nothing', function () {
expect($('#fruits').after()[0].tagName).toBe('ul');
expect($fruits.after()[0].tagName).toBe('ul');
});

it('(html) : should add element as next sibling', function () {
Expand Down
7 changes: 7 additions & 0 deletions test/api/traversing.js
Original file line number Diff line number Diff line change
Expand Up @@ -578,6 +578,13 @@ describe('$(...)', function () {
expect(result).toHaveLength(1);
expect(result[0].attribs.id).toBe('fruits');
});

it('(cheerio object) : should return all parents until body element', function () {
var body = $('body')[0];
var result = $('.carrot').parentsUntil(body);
expect(result).toHaveLength(2);
expect(result.eq(0).is('ul#vegetables')).toBe(true);
});
});

describe('.parent', function () {
Expand Down
4 changes: 4 additions & 0 deletions test/cheerio.js
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,10 @@ describe('cheerio', function () {
expect($empty.each).toBe(cheerio.prototype.each);
});

it('cheerio.html(null) should return a "" string', function () {
expect(cheerio.html(null)).toBe('');
});

it('should set html(number) as a string', function () {
var $elem = cheerio('<div>');
$elem.html(123);
Expand Down
9 changes: 9 additions & 0 deletions test/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,15 @@ describe('parse', function () {
expect(root.childNodes[0].type).toBe('directive');
});

it('should simply return root ', function () {
var oldroot = parse(basic, defaultOpts, true);
var root = parse(oldroot, defaultOpts, true);
expect(root).toBe(oldroot);
rootTest(root);
expect(root.childNodes).toHaveLength(1);
expect(root.childNodes[0].tagName).toBe('html');
});

it('should expose the DOM level 1 API', function () {
var root = parse(
'<div><a></a><span></span><p></p></div>',
Expand Down

0 comments on commit 09cde82

Please sign in to comment.