From 5aa4272291259b256a8bd19f0e00d251857f6d95 Mon Sep 17 00:00:00 2001 From: XhmikosR Date: Sat, 9 Jan 2021 21:42:06 +0200 Subject: [PATCH] test: prefer using `.toBeUndefined()` (#1659) --- test/api/attributes.js | 48 ++++++++++++++++++++-------------------- test/api/css.js | 4 ++-- test/api/manipulation.js | 2 +- test/api/traversing.js | 4 ++-- test/cheerio.js | 2 +- 5 files changed, 30 insertions(+), 30 deletions(-) diff --git a/test/api/attributes.js b/test/api/attributes.js index 7f7a085fcb..65c7623894 100644 --- a/test/api/attributes.js +++ b/test/api/attributes.js @@ -21,7 +21,7 @@ describe('$(...)', function () { it('(invalid key) : invalid attr should get undefined', function () { var attr = $('.apple').attr('lol'); - expect(attr).toBe(undefined); + expect(attr).toBeUndefined(); }); it('(valid key) : valid attr should get value', function () { @@ -44,14 +44,14 @@ describe('$(...)', function () { var $el = cheerio('
').attr('class', 'pear'); expect($el[0].attribs['class']).toBe('pear'); - expect($el[1].attribs).toBe(undefined); + expect($el[1].attribs).toBeUndefined(); expect($el[2].attribs['class']).toBe('pear'); }); it('(key, value) : should return an empty object for an empty object', function () { var $src = $().attr('key', 'value'); expect($src.length).toBe(0); - expect($src[0]).toBe(undefined); + expect($src[0]).toBeUndefined(); }); it('(map) : object map should set multiple attributes', function () { @@ -106,7 +106,7 @@ describe('$(...)', function () { $apple.attr('autofocus', 'autofocus'); expect($apple.attr('autofocus')).toBe('autofocus'); $apple.removeAttr('autofocus'); - expect($apple.attr('autofocus')).toBe(undefined); + expect($apple.attr('autofocus')).toBeUndefined(); }); it('(key, value) : should remove non-boolean attributes with names or values similar to boolean ones', function () { @@ -114,14 +114,14 @@ describe('$(...)', function () { $apple.attr('data-autofocus', 'autofocus'); expect($apple.attr('data-autofocus')).toBe('autofocus'); $apple.removeAttr('data-autofocus'); - expect($apple.attr('data-autofocus')).toBe(undefined); + expect($apple.attr('data-autofocus')).toBeUndefined(); }); it('(key, value) : should remove attributes when called with null value', function () { var $pear = $('.pear').attr('autofocus', 'autofocus'); expect($pear.attr('autofocus')).toBe('autofocus'); $pear.attr('autofocus', null); - expect($pear.attr('autofocus')).toBe(undefined); + expect($pear.attr('autofocus')).toBeUndefined(); }); it('(map) : should remove attributes with null values', function () { @@ -132,7 +132,7 @@ describe('$(...)', function () { expect($pear.attr('autofocus')).toBe('autofocus'); expect($pear.attr('style')).toBe('color:red'); $pear.attr({ autofocus: null, style: 'color:blue' }); - expect($pear.attr('autofocus')).toBe(undefined); + expect($pear.attr('autofocus')).toBeUndefined(); expect($pear.attr('style')).toBe('color:blue'); }); @@ -149,7 +149,7 @@ describe('$(...)', function () { it('(chaining) setting attr to undefined returns a $', function () { var $pear = $('.pear').attr('foo', undefined); expect($('.pear')).toHaveLength(1); - expect($('.pear').attr('foo')).toBe('undefined'); + expect($('.pear').attr('foo')).toBe('undefined'); // TODO this is stringified undefined expect($pear).toBeInstanceOf($); }); }); @@ -175,9 +175,9 @@ describe('$(...)', function () { }); it('(invalid key) : invalid prop should get undefined', function () { - expect(checkbox.prop('lol')).toBe(undefined); - expect(checkbox.prop(4)).toBe(undefined); - expect(checkbox.prop(true)).toBe(undefined); + expect(checkbox.prop('lol')).toBeUndefined(); + expect(checkbox.prop(4)).toBeUndefined(); + expect(checkbox.prop(true)).toBeUndefined(); }); it('(key, value) : should set prop', function () { @@ -193,7 +193,7 @@ describe('$(...)', function () { expect(checkbox.attr('checked')).toBe('checked'); checkbox.prop('checked', false); expect(checkbox.prop('checked')).toBe(false); - expect(checkbox.attr('checked')).toBe(undefined); + expect(checkbox.attr('checked')).toBeUndefined(); checkbox.prop('checked', true); expect(checkbox.prop('checked')).toBe(true); expect(checkbox.attr('checked')).toBe('checked'); @@ -205,7 +205,7 @@ describe('$(...)', function () { imgs.prop('src', '#').prop('namespace', nsHtml); expect(imgs.prop('namespace')).toBe(nsHtml); imgs.prop('attribs', null); - expect(imgs.prop('src')).toBe(undefined); + expect(imgs.prop('src')).toBeUndefined(); }); it('(map) : object map should set multiple props', function () { @@ -231,8 +231,8 @@ describe('$(...)', function () { }); it('(invalid element/tag) : prop should return undefined', function () { - expect($(undefined).prop('prop')).toBe(undefined); - expect($(null).prop('prop')).toBe(undefined); + expect($(undefined).prop('prop')).toBeUndefined(); + expect($(null).prop('prop')).toBeUndefined(); }); it('("outerHTML") : should render properly', function () { @@ -292,12 +292,12 @@ describe('$(...)', function () { it('() : no data attribute should return an empty object', function () { var data = $('.cailler').data(); expect(Object.keys(data)).toHaveLength(0); - expect($('.free').data()).toBe(undefined); + expect($('.free').data()).toBeUndefined(); }); it('(invalid key) : invalid data attribute should return `undefined`', function () { var data = $('.frey').data('lol'); - expect(data).toBe(undefined); + expect(data).toBeUndefined(); }); it('(valid key) : valid data attribute should get value', function () { @@ -493,11 +493,11 @@ describe('$(...)', function () { }); it('(): with no selector matches should return nothing', function () { var val = $('.nasty').val(); - expect(val).toBe(undefined); + expect(val).toBeUndefined(); }); it('(invalid value): should only handle arrays when it has the attribute multiple', function () { var val = $('select#one').val([]); - expect(val).not.toBe(undefined); + expect(val).not.toBeUndefined(); }); it('(value): on input text should set value', function () { var element = $('input[type="text"]').val('test'); @@ -528,9 +528,9 @@ describe('$(...)', function () { describe('.removeAttr', function () { it('(key) : should remove a single attr', function () { var $fruits = $('#fruits'); - expect($fruits.attr('id')).not.toBe(undefined); + expect($fruits.attr('id')).not.toBeUndefined(); $fruits.removeAttr('id'); - expect($fruits.attr('id')).toBe(undefined); + expect($fruits.attr('id')).toBeUndefined(); }); it('(key key): should remove multiple attrs', function () { @@ -542,8 +542,8 @@ describe('$(...)', function () { expect($apple.attr('class')).toBe('apple'); expect($apple.attr('size')).toBe('small'); $apple.removeAttr('id class'); - expect($apple.attr('id')).toBe(undefined); - expect($apple.attr('class')).toBe(undefined); + expect($apple.attr('id')).toBeUndefined(); + expect($apple.attr('class')).toBeUndefined(); expect($apple.attr('size')).toBe('small'); }); @@ -652,7 +652,7 @@ describe('$(...)', function () { it('() : should remove all the classes', function () { $('.pear').addClass('fruit'); $('.pear').removeClass(); - expect($('.pear').attr('class')).toBe(undefined); + expect($('.pear').attr('class')).toBeUndefined(); }); it('("") : should not modify class list', function () { diff --git a/test/api/css.js b/test/api/css.js index c566a33af3..c0aca4b27d 100644 --- a/test/api/css.js +++ b/test/api/css.js @@ -50,12 +50,12 @@ describe('$(...)', function () { it('(prop): should return undefined for unmatched elements', function () { var $ = cheerio.load('
  • '); - expect($('ul').css('background-image')).toStrictEqual(undefined); + expect($('ul').css('background-image')).toBeUndefined(); }); it('(prop): should return undefined for unmatched styles', function () { var el = cheerio('
  • '); - expect(el.css('margin')).toStrictEqual(undefined); + expect(el.css('margin')).toBeUndefined(); }); describe('(prop, function):', function () { diff --git a/test/api/manipulation.js b/test/api/manipulation.js index ced60650aa..ba594a6c6b 100644 --- a/test/api/manipulation.js +++ b/test/api/manipulation.js @@ -504,7 +504,7 @@ describe('$(...)', function () { $new.wrapAll(function (index) { expect(this).toBe($new[0]); - expect(index).toBe(undefined); + expect(index).toBeUndefined(); }); }); }); diff --git a/test/api/traversing.js b/test/api/traversing.js index eea17f020a..baa44b1c19 100644 --- a/test/api/traversing.js +++ b/test/api/traversing.js @@ -896,7 +896,7 @@ describe('$(...)', function () { var $src = $(); var $first = $src.first(); expect($first.length).toBe(0); - expect($first[0]).toBe(undefined); + expect($first[0]).toBeUndefined(); }); }); @@ -912,7 +912,7 @@ describe('$(...)', function () { var $src = $(); var $last = $src.last(); expect($last.length).toBe(0); - expect($last[0]).toBe(undefined); + expect($last[0]).toBeUndefined(); }); }); diff --git a/test/cheerio.js b/test/cheerio.js index f38eb00e73..bbf23528f7 100644 --- a/test/cheerio.js +++ b/test/cheerio.js @@ -372,7 +372,7 @@ describe('cheerio', function () { $a.prototype.foo = function () {}; - expect($b('div').foo).toBe(undefined); + expect($b('div').foo).toBeUndefined(); }); }); });