Skip to content

Commit d4f2a15

Browse files
Added some tests
1 parent 0a2e075 commit d4f2a15

1 file changed

Lines changed: 48 additions & 8 deletions

File tree

test/index.js

Lines changed: 48 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,10 @@ QUnit.test( "removeClass", function( assert ) {
160160
assert.equal(hasClass, false, "removeClass works with classes containing special characters" );
161161
});
162162

163-
//TODO: removeProp
163+
QUnit.test( "removeProp", function( assert ) {
164+
$('.prop-fixture').prop('foo',123).removeProp('foo');
165+
assert.equal($('.prop-fixture').prop('foo'), undefined, "removeProp Passed!" );
166+
});
164167

165168
QUnit.test( "toggleClass", function( assert ) {
166169

@@ -502,7 +505,17 @@ QUnit.test( "val", function( assert ) {
502505
$('input[type=text]').val(0);
503506
assert.equal($('input[type=text]').val(), 0, "val set Passed!" );
504507
assert.equal($('select[name=select]').val(), "selected", "val get select Passed!" );
505-
assert.equal($('select[name=select-multiple]').val(), "option-1,option-2", "val get select multiple Passed!" );
508+
$('select[name=select]').val('not-selected');
509+
assert.equal($('select[name=select]').val(), "not-selected", "val set select Passed!" );
510+
assert.deepEqual($('select[name=select-multiple]').val(), ['option-1', 'option-2'], "val get select multiple Passed!" );
511+
$('input[type=text]').val(null);
512+
$('select[name=select-multiple]').val(null);
513+
assert.deepEqual($('input[type=text]').val(), '', "val set to null Passed!" );
514+
assert.deepEqual($('select[name=select-multiple]').val(), [], "val set to null Passed!" );
515+
$('select[name=select-multiple]').val(['option-1']);
516+
assert.deepEqual($('select[name=select-multiple]').val(), ['option-1'], "val set 1 option in select multiple Passed!" );
517+
$('select[name=select-multiple]').val(['option-1', 'option-2']);
518+
assert.deepEqual($('select[name=select-multiple]').val(), ['option-1', 'option-2'], "val set 2 options in select multiple Passed!" );
506519
});
507520

508521
/* MANIPULATION */
@@ -626,8 +639,19 @@ QUnit.test( "remove", function( assert ) {
626639
assert.equal(i, 1, "remove events Passed!" );
627640
});
628641

629-
//TODO: replaceAll
630-
//TODO: replaceWith
642+
QUnit.test( "replaceAll", function( assert ) {
643+
var html = '<div class="qsa-fixture" data-foo="123"><p>Paragraph</p></div>';
644+
$(html).replaceAll('.qsa-fixture');
645+
$('.qsa-fixture').get ().forEach ( function ( ele ) {
646+
assert.equal($(ele)[0].outerHTML, html, "replaceAll Passed!" );
647+
});
648+
});
649+
650+
QUnit.test( "replaceWith", function( assert ) {
651+
var html = '<div class="class-fixture" data-foo="123"><p>Paragraph</p></div>';
652+
$('.class-fixture').replaceWith(html);
653+
assert.equal($('.class-fixture')[0].outerHTML, html, "replaceWith Passed!" );
654+
});
631655

632656
QUnit.test( "text", function( assert ) {
633657
$('.class-fixture').text('Text Content');
@@ -638,9 +662,21 @@ QUnit.test( "text", function( assert ) {
638662

639663
/* OFFSET */
640664

641-
//TODO: offsetParent
642-
//TODO: offset
643-
//TODO: position
665+
QUnit.test( "offsetParent", function( assert ) {
666+
assert.equal($('.class-fixture').offsetParent ()[0], $('#qunit-fixture')[0], "offsetParent Passed!" );
667+
});
668+
669+
QUnit.test( "offset", function( assert ) {
670+
var html = '<div class="offset-fixture" style="position: fixed; top: 200px; left: 100px;"></div>';
671+
$('.class-fixture').html(html);
672+
assert.deepEqual($('.offset-fixture').offset (), {top:200,left:100}, "offset Passed!" );
673+
});
674+
675+
QUnit.test( "position", function( assert ) {
676+
var html = '<div class="offset-fixture" style="position: fixed; top: 200px; left: 100px;"><div class="position-fixture" style="position: absolute; top: 20px; left: 10px;"></div></div>';
677+
$('.class-fixture').html(html);
678+
assert.deepEqual($('.position-fixture').position (), {top:20,left:10}, "position Passed!" );
679+
});
644680

645681
/* TRAVERSAL */
646682

@@ -759,7 +795,11 @@ QUnit.test( "$.parseHTML", function( assert ) {
759795
assert.equal($.parseHTML('<a>')[0].outerHTML, '<a></a>' , "$.parseHTML Passed!" );
760796
});
761797

762-
//TODO: prefixedProp
798+
QUnit.test( "$.prefixedProp", function( assert ) {
799+
assert.equal($.prefixedProp( 'foo-bar' ), undefined, "$.prefixedProp returns undefined Passed!" );
800+
assert.equal($.prefixedProp( '--foo-bar' ), '--foo-bar', "$.prefixedProp works with css variables Passed!" );
801+
assert.equal($.prefixedProp( 'width' ), 'width', "$.prefixedProp works with basic css properties Passed!" );
802+
});
763803

764804
QUnit.test( "$.unique", function( assert ) {
765805
var test = [ $("#id-fixture")[0], $("#id-fixture")[0] ];

0 commit comments

Comments
 (0)