Skip to content

Commit 4859684

Browse files
authored
Prefer Jest's toBe true/false matcher. (#1639)
Also, remove some trailing spaces from descriptions.
1 parent bfa114e commit 4859684

File tree

3 files changed

+244
-244
lines changed

3 files changed

+244
-244
lines changed

test/api/attributes.js

Lines changed: 85 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ describe('$(...)', function () {
283283
expect(Object.keys(data)).toHaveLength(0);
284284
});
285285

286-
it('(invalid key) : invalid data attribute should return `undefined` ', function () {
286+
it('(invalid key) : invalid data attribute should return `undefined`', function () {
287287
var data = $('.frey').data('lol');
288288
expect(data).toBe(undefined);
289289
});
@@ -545,37 +545,37 @@ describe('$(...)', function () {
545545

546546
it('(valid class) : should return true', function () {
547547
var cls = $('.apple').hasClass('apple');
548-
expect(cls).toBeTruthy();
548+
expect(cls).toBe(true);
549549

550-
expect(test('foo').hasClass('foo')).toBeTruthy();
551-
expect(test('foo bar').hasClass('foo')).toBeTruthy();
552-
expect(test('bar foo').hasClass('foo')).toBeTruthy();
553-
expect(test('bar foo bar').hasClass('foo')).toBeTruthy();
550+
expect(test('foo').hasClass('foo')).toBe(true);
551+
expect(test('foo bar').hasClass('foo')).toBe(true);
552+
expect(test('bar foo').hasClass('foo')).toBe(true);
553+
expect(test('bar foo bar').hasClass('foo')).toBe(true);
554554
});
555555

556556
it('(invalid class) : should return false', function () {
557557
var cls = $('#fruits').hasClass('fruits');
558-
expect(cls).toBeFalsy();
559-
expect(test('foo-bar').hasClass('foo')).toBeFalsy();
560-
expect(test('foo-bar').hasClass('foo')).toBeFalsy();
561-
expect(test('foo-bar').hasClass('foo-ba')).toBeFalsy();
558+
expect(cls).toBe(false);
559+
expect(test('foo-bar').hasClass('foo')).toBe(false);
560+
expect(test('foo-bar').hasClass('foo')).toBe(false);
561+
expect(test('foo-bar').hasClass('foo-ba')).toBe(false);
562562
});
563563

564564
it('should check multiple classes', function () {
565565
// Add a class
566566
$('.apple').addClass('red');
567-
expect($('.apple').hasClass('apple')).toBeTruthy();
568-
expect($('.apple').hasClass('red')).toBeTruthy();
567+
expect($('.apple').hasClass('apple')).toBe(true);
568+
expect($('.apple').hasClass('red')).toBe(true);
569569

570570
// Remove one and test again
571571
$('.apple').removeClass('apple');
572-
expect($('li').eq(0).hasClass('apple')).toBeFalsy();
572+
expect($('li').eq(0).hasClass('apple')).toBe(false);
573573
});
574574

575575
it('(empty string argument) : should return false', function () {
576-
expect(test('foo').hasClass('')).toBeFalsy();
577-
expect(test('foo bar').hasClass('')).toBeFalsy();
578-
expect(test('foo bar').removeClass('foo').hasClass('')).toBeFalsy();
576+
expect(test('foo').hasClass('')).toBe(false);
577+
expect(test('foo bar').hasClass('')).toBe(false);
578+
expect(test('foo bar').removeClass('foo').hasClass('')).toBe(false);
579579
});
580580
});
581581

@@ -584,28 +584,28 @@ describe('$(...)', function () {
584584
var $fruits = $('#fruits');
585585
$fruits.addClass('fruits');
586586
var cls = $fruits.hasClass('fruits');
587-
expect(cls).toBeTruthy();
587+
expect(cls).toBe(true);
588588
});
589589

590590
it('(single class) : should add the class to the element', function () {
591591
$('.apple').addClass('fruit');
592592
var cls = $('.apple').hasClass('fruit');
593-
expect(cls).toBeTruthy();
593+
expect(cls).toBe(true);
594594
});
595595

596596
it('(class): adds classes to many selected items', function () {
597597
$('li').addClass('fruit');
598-
expect($('.apple').hasClass('fruit')).toBeTruthy();
599-
expect($('.orange').hasClass('fruit')).toBeTruthy();
600-
expect($('.pear').hasClass('fruit')).toBeTruthy();
598+
expect($('.apple').hasClass('fruit')).toBe(true);
599+
expect($('.orange').hasClass('fruit')).toBe(true);
600+
expect($('.pear').hasClass('fruit')).toBe(true);
601601
});
602602

603603
it('(class class class) : should add multiple classes to the element', function () {
604604
$('.apple').addClass('fruit red tasty');
605-
expect($('.apple').hasClass('apple')).toBeTruthy();
606-
expect($('.apple').hasClass('fruit')).toBeTruthy();
607-
expect($('.apple').hasClass('red')).toBeTruthy();
608-
expect($('.apple').hasClass('tasty')).toBeTruthy();
605+
expect($('.apple').hasClass('apple')).toBe(true);
606+
expect($('.apple').hasClass('fruit')).toBe(true);
607+
expect($('.apple').hasClass('red')).toBe(true);
608+
expect($('.apple').hasClass('tasty')).toBe(true);
609609
});
610610

611611
it('(fn) : should add classes returned from the function', function () {
@@ -626,10 +626,10 @@ describe('$(...)', function () {
626626
[2, 'pear'],
627627
]);
628628
expect(thisVals).toStrictEqual([$fruits[0], $fruits[1], $fruits[2]]);
629-
expect($fruits.eq(0).hasClass('apple')).toBeTruthy();
630-
expect($fruits.eq(0).hasClass('red')).toBeTruthy();
631-
expect($fruits.eq(1).hasClass('orange')).toBeTruthy();
632-
expect($fruits.eq(2).hasClass('pear')).toBeTruthy();
629+
expect($fruits.eq(0).hasClass('apple')).toBe(true);
630+
expect($fruits.eq(0).hasClass('red')).toBe(true);
631+
expect($fruits.eq(1).hasClass('orange')).toBe(true);
632+
expect($fruits.eq(2).hasClass('pear')).toBe(true);
633633
});
634634
});
635635

@@ -648,7 +648,7 @@ describe('$(...)', function () {
648648

649649
it('(invalid class) : should not remove anything', function () {
650650
$('.pear').removeClass('fruit');
651-
expect($('.pear').hasClass('pear')).toBeTruthy();
651+
expect($('.pear').hasClass('pear')).toBe(true);
652652
});
653653

654654
it('(no class attribute) : should not throw an exception', function () {
@@ -661,36 +661,36 @@ describe('$(...)', function () {
661661

662662
it('(single class) : should remove a single class from the element', function () {
663663
$('.pear').addClass('fruit');
664-
expect($('.pear').hasClass('fruit')).toBeTruthy();
664+
expect($('.pear').hasClass('fruit')).toBe(true);
665665
$('.pear').removeClass('fruit');
666-
expect($('.pear').hasClass('fruit')).toBeFalsy();
667-
expect($('.pear').hasClass('pear')).toBeTruthy();
666+
expect($('.pear').hasClass('fruit')).toBe(false);
667+
expect($('.pear').hasClass('pear')).toBe(true);
668668
});
669669

670670
it('(single class) : should remove a single class from multiple classes on the element', function () {
671671
$('.pear').addClass('fruit green tasty');
672-
expect($('.pear').hasClass('fruit')).toBeTruthy();
673-
expect($('.pear').hasClass('green')).toBeTruthy();
674-
expect($('.pear').hasClass('tasty')).toBeTruthy();
672+
expect($('.pear').hasClass('fruit')).toBe(true);
673+
expect($('.pear').hasClass('green')).toBe(true);
674+
expect($('.pear').hasClass('tasty')).toBe(true);
675675

676676
$('.pear').removeClass('green');
677-
expect($('.pear').hasClass('fruit')).toBeTruthy();
678-
expect($('.pear').hasClass('green')).toBeFalsy();
679-
expect($('.pear').hasClass('tasty')).toBeTruthy();
677+
expect($('.pear').hasClass('fruit')).toBe(true);
678+
expect($('.pear').hasClass('green')).toBe(false);
679+
expect($('.pear').hasClass('tasty')).toBe(true);
680680
});
681681

682682
it('(class class class) : should remove multiple classes from the element', function () {
683683
$('.apple').addClass('fruit red tasty');
684-
expect($('.apple').hasClass('apple')).toBeTruthy();
685-
expect($('.apple').hasClass('fruit')).toBeTruthy();
686-
expect($('.apple').hasClass('red')).toBeTruthy();
687-
expect($('.apple').hasClass('tasty')).toBeTruthy();
684+
expect($('.apple').hasClass('apple')).toBe(true);
685+
expect($('.apple').hasClass('fruit')).toBe(true);
686+
expect($('.apple').hasClass('red')).toBe(true);
687+
expect($('.apple').hasClass('tasty')).toBe(true);
688688

689689
$('.apple').removeClass('apple red tasty');
690-
expect($('.fruit').hasClass('apple')).toBeFalsy();
691-
expect($('.fruit').hasClass('red')).toBeFalsy();
692-
expect($('.fruit').hasClass('tasty')).toBeFalsy();
693-
expect($('.fruit').hasClass('fruit')).toBeTruthy();
690+
expect($('.fruit').hasClass('apple')).toBe(false);
691+
expect($('.fruit').hasClass('red')).toBe(false);
692+
expect($('.fruit').hasClass('tasty')).toBe(false);
693+
expect($('.fruit').hasClass('fruit')).toBe(true);
694694
});
695695

696696
it('(class) : should remove all occurrences of a class name', function () {
@@ -716,10 +716,10 @@ describe('$(...)', function () {
716716
[2, 'pear'],
717717
]);
718718
expect(thisVals).toStrictEqual([$fruits[0], $fruits[1], $fruits[2]]);
719-
expect($fruits.eq(0).hasClass('apple')).toBeFalsy();
720-
expect($fruits.eq(0).hasClass('red')).toBeFalsy();
721-
expect($fruits.eq(1).hasClass('orange')).toBeTruthy();
722-
expect($fruits.eq(2).hasClass('pear')).toBeTruthy();
719+
expect($fruits.eq(0).hasClass('apple')).toBe(false);
720+
expect($fruits.eq(0).hasClass('red')).toBe(false);
721+
expect($fruits.eq(1).hasClass('orange')).toBe(true);
722+
expect($fruits.eq(2).hasClass('pear')).toBe(true);
723723
});
724724

725725
it('(fn) : should no op elements without attributes', function () {
@@ -734,26 +734,26 @@ describe('$(...)', function () {
734734
describe('.toggleClass', function () {
735735
it('(class class) : should toggle multiple classes from the element', function () {
736736
$('.apple').addClass('fruit');
737-
expect($('.apple').hasClass('apple')).toBeTruthy();
738-
expect($('.apple').hasClass('fruit')).toBeTruthy();
739-
expect($('.apple').hasClass('red')).toBeFalsy();
737+
expect($('.apple').hasClass('apple')).toBe(true);
738+
expect($('.apple').hasClass('fruit')).toBe(true);
739+
expect($('.apple').hasClass('red')).toBe(false);
740740

741741
$('.apple').toggleClass('apple red');
742-
expect($('.fruit').hasClass('apple')).toBeFalsy();
743-
expect($('.fruit').hasClass('red')).toBeTruthy();
744-
expect($('.fruit').hasClass('fruit')).toBeTruthy();
742+
expect($('.fruit').hasClass('apple')).toBe(false);
743+
expect($('.fruit').hasClass('red')).toBe(true);
744+
expect($('.fruit').hasClass('fruit')).toBe(true);
745745
});
746746

747747
it('(class class, true) : should add multiple classes to the element', function () {
748748
$('.apple').addClass('fruit');
749-
expect($('.apple').hasClass('apple')).toBeTruthy();
750-
expect($('.apple').hasClass('fruit')).toBeTruthy();
751-
expect($('.apple').hasClass('red')).toBeFalsy();
749+
expect($('.apple').hasClass('apple')).toBe(true);
750+
expect($('.apple').hasClass('fruit')).toBe(true);
751+
expect($('.apple').hasClass('red')).toBe(false);
752752

753753
$('.apple').toggleClass('apple red', true);
754-
expect($('.fruit').hasClass('apple')).toBeTruthy();
755-
expect($('.fruit').hasClass('red')).toBeTruthy();
756-
expect($('.fruit').hasClass('fruit')).toBeTruthy();
754+
expect($('.fruit').hasClass('apple')).toBe(true);
755+
expect($('.fruit').hasClass('red')).toBe(true);
756+
expect($('.fruit').hasClass('fruit')).toBe(true);
757757
});
758758

759759
it('(class true) : should add only one instance of class', function () {
@@ -764,41 +764,41 @@ describe('$(...)', function () {
764764

765765
it('(class class, false) : should remove multiple classes from the element', function () {
766766
$('.apple').addClass('fruit');
767-
expect($('.apple').hasClass('apple')).toBeTruthy();
768-
expect($('.apple').hasClass('fruit')).toBeTruthy();
769-
expect($('.apple').hasClass('red')).toBeFalsy();
767+
expect($('.apple').hasClass('apple')).toBe(true);
768+
expect($('.apple').hasClass('fruit')).toBe(true);
769+
expect($('.apple').hasClass('red')).toBe(false);
770770

771771
$('.apple').toggleClass('apple red', false);
772-
expect($('.fruit').hasClass('apple')).toBeFalsy();
773-
expect($('.fruit').hasClass('red')).toBeFalsy();
774-
expect($('.fruit').hasClass('fruit')).toBeTruthy();
772+
expect($('.fruit').hasClass('apple')).toBe(false);
773+
expect($('.fruit').hasClass('red')).toBe(false);
774+
expect($('.fruit').hasClass('fruit')).toBe(true);
775775
});
776776

777777
it('(fn) : should toggle classes returned from the function', function () {
778778
$ = cheerio.load(food);
779779

780780
$('.apple').addClass('fruit');
781781
$('.carrot').addClass('vegetable');
782-
expect($('.apple').hasClass('fruit')).toBeTruthy();
783-
expect($('.apple').hasClass('vegetable')).toBeFalsy();
784-
expect($('.orange').hasClass('fruit')).toBeFalsy();
785-
expect($('.orange').hasClass('vegetable')).toBeFalsy();
786-
expect($('.carrot').hasClass('fruit')).toBeFalsy();
787-
expect($('.carrot').hasClass('vegetable')).toBeTruthy();
788-
expect($('.sweetcorn').hasClass('fruit')).toBeFalsy();
789-
expect($('.sweetcorn').hasClass('vegetable')).toBeFalsy();
782+
expect($('.apple').hasClass('fruit')).toBe(true);
783+
expect($('.apple').hasClass('vegetable')).toBe(false);
784+
expect($('.orange').hasClass('fruit')).toBe(false);
785+
expect($('.orange').hasClass('vegetable')).toBe(false);
786+
expect($('.carrot').hasClass('fruit')).toBe(false);
787+
expect($('.carrot').hasClass('vegetable')).toBe(true);
788+
expect($('.sweetcorn').hasClass('fruit')).toBe(false);
789+
expect($('.sweetcorn').hasClass('vegetable')).toBe(false);
790790

791791
$('li').toggleClass(function () {
792792
return $(this).parent().is('#fruits') ? 'fruit' : 'vegetable';
793793
});
794-
expect($('.apple').hasClass('fruit')).toBeFalsy();
795-
expect($('.apple').hasClass('vegetable')).toBeFalsy();
796-
expect($('.orange').hasClass('fruit')).toBeTruthy();
797-
expect($('.orange').hasClass('vegetable')).toBeFalsy();
798-
expect($('.carrot').hasClass('fruit')).toBeFalsy();
799-
expect($('.carrot').hasClass('vegetable')).toBeFalsy();
800-
expect($('.sweetcorn').hasClass('fruit')).toBeFalsy();
801-
expect($('.sweetcorn').hasClass('vegetable')).toBeTruthy();
794+
expect($('.apple').hasClass('fruit')).toBe(false);
795+
expect($('.apple').hasClass('vegetable')).toBe(false);
796+
expect($('.orange').hasClass('fruit')).toBe(true);
797+
expect($('.orange').hasClass('vegetable')).toBe(false);
798+
expect($('.carrot').hasClass('fruit')).toBe(false);
799+
expect($('.carrot').hasClass('vegetable')).toBe(false);
800+
expect($('.sweetcorn').hasClass('fruit')).toBe(false);
801+
expect($('.sweetcorn').hasClass('vegetable')).toBe(true);
802802
});
803803

804804
it('(fn) : should work with no initial class attribute', function () {

0 commit comments

Comments
 (0)