Skip to content

Commit 5aa4272

Browse files
authored
test: prefer using .toBeUndefined() (#1659)
1 parent 8e63918 commit 5aa4272

File tree

5 files changed

+30
-30
lines changed

5 files changed

+30
-30
lines changed

test/api/attributes.js

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ describe('$(...)', function () {
2121

2222
it('(invalid key) : invalid attr should get undefined', function () {
2323
var attr = $('.apple').attr('lol');
24-
expect(attr).toBe(undefined);
24+
expect(attr).toBeUndefined();
2525
});
2626

2727
it('(valid key) : valid attr should get value', function () {
@@ -44,14 +44,14 @@ describe('$(...)', function () {
4444
var $el = cheerio('<div></div> <div></div>').attr('class', 'pear');
4545

4646
expect($el[0].attribs['class']).toBe('pear');
47-
expect($el[1].attribs).toBe(undefined);
47+
expect($el[1].attribs).toBeUndefined();
4848
expect($el[2].attribs['class']).toBe('pear');
4949
});
5050

5151
it('(key, value) : should return an empty object for an empty object', function () {
5252
var $src = $().attr('key', 'value');
5353
expect($src.length).toBe(0);
54-
expect($src[0]).toBe(undefined);
54+
expect($src[0]).toBeUndefined();
5555
});
5656

5757
it('(map) : object map should set multiple attributes', function () {
@@ -106,22 +106,22 @@ describe('$(...)', function () {
106106
$apple.attr('autofocus', 'autofocus');
107107
expect($apple.attr('autofocus')).toBe('autofocus');
108108
$apple.removeAttr('autofocus');
109-
expect($apple.attr('autofocus')).toBe(undefined);
109+
expect($apple.attr('autofocus')).toBeUndefined();
110110
});
111111

112112
it('(key, value) : should remove non-boolean attributes with names or values similar to boolean ones', function () {
113113
var $apple = $('.apple');
114114
$apple.attr('data-autofocus', 'autofocus');
115115
expect($apple.attr('data-autofocus')).toBe('autofocus');
116116
$apple.removeAttr('data-autofocus');
117-
expect($apple.attr('data-autofocus')).toBe(undefined);
117+
expect($apple.attr('data-autofocus')).toBeUndefined();
118118
});
119119

120120
it('(key, value) : should remove attributes when called with null value', function () {
121121
var $pear = $('.pear').attr('autofocus', 'autofocus');
122122
expect($pear.attr('autofocus')).toBe('autofocus');
123123
$pear.attr('autofocus', null);
124-
expect($pear.attr('autofocus')).toBe(undefined);
124+
expect($pear.attr('autofocus')).toBeUndefined();
125125
});
126126

127127
it('(map) : should remove attributes with null values', function () {
@@ -132,7 +132,7 @@ describe('$(...)', function () {
132132
expect($pear.attr('autofocus')).toBe('autofocus');
133133
expect($pear.attr('style')).toBe('color:red');
134134
$pear.attr({ autofocus: null, style: 'color:blue' });
135-
expect($pear.attr('autofocus')).toBe(undefined);
135+
expect($pear.attr('autofocus')).toBeUndefined();
136136
expect($pear.attr('style')).toBe('color:blue');
137137
});
138138

@@ -149,7 +149,7 @@ describe('$(...)', function () {
149149
it('(chaining) setting attr to undefined returns a $', function () {
150150
var $pear = $('.pear').attr('foo', undefined);
151151
expect($('.pear')).toHaveLength(1);
152-
expect($('.pear').attr('foo')).toBe('undefined');
152+
expect($('.pear').attr('foo')).toBe('undefined'); // TODO this is stringified undefined
153153
expect($pear).toBeInstanceOf($);
154154
});
155155
});
@@ -175,9 +175,9 @@ describe('$(...)', function () {
175175
});
176176

177177
it('(invalid key) : invalid prop should get undefined', function () {
178-
expect(checkbox.prop('lol')).toBe(undefined);
179-
expect(checkbox.prop(4)).toBe(undefined);
180-
expect(checkbox.prop(true)).toBe(undefined);
178+
expect(checkbox.prop('lol')).toBeUndefined();
179+
expect(checkbox.prop(4)).toBeUndefined();
180+
expect(checkbox.prop(true)).toBeUndefined();
181181
});
182182

183183
it('(key, value) : should set prop', function () {
@@ -193,7 +193,7 @@ describe('$(...)', function () {
193193
expect(checkbox.attr('checked')).toBe('checked');
194194
checkbox.prop('checked', false);
195195
expect(checkbox.prop('checked')).toBe(false);
196-
expect(checkbox.attr('checked')).toBe(undefined);
196+
expect(checkbox.attr('checked')).toBeUndefined();
197197
checkbox.prop('checked', true);
198198
expect(checkbox.prop('checked')).toBe(true);
199199
expect(checkbox.attr('checked')).toBe('checked');
@@ -205,7 +205,7 @@ describe('$(...)', function () {
205205
imgs.prop('src', '#').prop('namespace', nsHtml);
206206
expect(imgs.prop('namespace')).toBe(nsHtml);
207207
imgs.prop('attribs', null);
208-
expect(imgs.prop('src')).toBe(undefined);
208+
expect(imgs.prop('src')).toBeUndefined();
209209
});
210210

211211
it('(map) : object map should set multiple props', function () {
@@ -231,8 +231,8 @@ describe('$(...)', function () {
231231
});
232232

233233
it('(invalid element/tag) : prop should return undefined', function () {
234-
expect($(undefined).prop('prop')).toBe(undefined);
235-
expect($(null).prop('prop')).toBe(undefined);
234+
expect($(undefined).prop('prop')).toBeUndefined();
235+
expect($(null).prop('prop')).toBeUndefined();
236236
});
237237

238238
it('("outerHTML") : should render properly', function () {
@@ -292,12 +292,12 @@ describe('$(...)', function () {
292292
it('() : no data attribute should return an empty object', function () {
293293
var data = $('.cailler').data();
294294
expect(Object.keys(data)).toHaveLength(0);
295-
expect($('.free').data()).toBe(undefined);
295+
expect($('.free').data()).toBeUndefined();
296296
});
297297

298298
it('(invalid key) : invalid data attribute should return `undefined`', function () {
299299
var data = $('.frey').data('lol');
300-
expect(data).toBe(undefined);
300+
expect(data).toBeUndefined();
301301
});
302302

303303
it('(valid key) : valid data attribute should get value', function () {
@@ -493,11 +493,11 @@ describe('$(...)', function () {
493493
});
494494
it('(): with no selector matches should return nothing', function () {
495495
var val = $('.nasty').val();
496-
expect(val).toBe(undefined);
496+
expect(val).toBeUndefined();
497497
});
498498
it('(invalid value): should only handle arrays when it has the attribute multiple', function () {
499499
var val = $('select#one').val([]);
500-
expect(val).not.toBe(undefined);
500+
expect(val).not.toBeUndefined();
501501
});
502502
it('(value): on input text should set value', function () {
503503
var element = $('input[type="text"]').val('test');
@@ -528,9 +528,9 @@ describe('$(...)', function () {
528528
describe('.removeAttr', function () {
529529
it('(key) : should remove a single attr', function () {
530530
var $fruits = $('#fruits');
531-
expect($fruits.attr('id')).not.toBe(undefined);
531+
expect($fruits.attr('id')).not.toBeUndefined();
532532
$fruits.removeAttr('id');
533-
expect($fruits.attr('id')).toBe(undefined);
533+
expect($fruits.attr('id')).toBeUndefined();
534534
});
535535

536536
it('(key key): should remove multiple attrs', function () {
@@ -542,8 +542,8 @@ describe('$(...)', function () {
542542
expect($apple.attr('class')).toBe('apple');
543543
expect($apple.attr('size')).toBe('small');
544544
$apple.removeAttr('id class');
545-
expect($apple.attr('id')).toBe(undefined);
546-
expect($apple.attr('class')).toBe(undefined);
545+
expect($apple.attr('id')).toBeUndefined();
546+
expect($apple.attr('class')).toBeUndefined();
547547
expect($apple.attr('size')).toBe('small');
548548
});
549549

@@ -652,7 +652,7 @@ describe('$(...)', function () {
652652
it('() : should remove all the classes', function () {
653653
$('.pear').addClass('fruit');
654654
$('.pear').removeClass();
655-
expect($('.pear').attr('class')).toBe(undefined);
655+
expect($('.pear').attr('class')).toBeUndefined();
656656
});
657657

658658
it('("") : should not modify class list', function () {

test/api/css.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,12 @@ describe('$(...)', function () {
5050

5151
it('(prop): should return undefined for unmatched elements', function () {
5252
var $ = cheerio.load('<li style="color:;position:absolute;">');
53-
expect($('ul').css('background-image')).toStrictEqual(undefined);
53+
expect($('ul').css('background-image')).toBeUndefined();
5454
});
5555

5656
it('(prop): should return undefined for unmatched styles', function () {
5757
var el = cheerio('<li style="color:;position:absolute;">');
58-
expect(el.css('margin')).toStrictEqual(undefined);
58+
expect(el.css('margin')).toBeUndefined();
5959
});
6060

6161
describe('(prop, function):', function () {

test/api/manipulation.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,7 @@ describe('$(...)', function () {
504504

505505
$new.wrapAll(function (index) {
506506
expect(this).toBe($new[0]);
507-
expect(index).toBe(undefined);
507+
expect(index).toBeUndefined();
508508
});
509509
});
510510
});

test/api/traversing.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -896,7 +896,7 @@ describe('$(...)', function () {
896896
var $src = $();
897897
var $first = $src.first();
898898
expect($first.length).toBe(0);
899-
expect($first[0]).toBe(undefined);
899+
expect($first[0]).toBeUndefined();
900900
});
901901
});
902902

@@ -912,7 +912,7 @@ describe('$(...)', function () {
912912
var $src = $();
913913
var $last = $src.last();
914914
expect($last.length).toBe(0);
915-
expect($last[0]).toBe(undefined);
915+
expect($last[0]).toBeUndefined();
916916
});
917917
});
918918

test/cheerio.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ describe('cheerio', function () {
372372

373373
$a.prototype.foo = function () {};
374374

375-
expect($b('div').foo).toBe(undefined);
375+
expect($b('div').foo).toBeUndefined();
376376
});
377377
});
378378
});

0 commit comments

Comments
 (0)