2 QUnit.module( 'jquery.mwExtension', QUnit.newMwEnvironment( {
3 // This entire module is deprecated.
4 // Surpress deprecation warnings in test output.
6 this.suppressWarnings();
8 teardown: function () {
9 this.restoreWarnings();
13 QUnit.test( 'String functions', 7, function ( assert ) {
14 assert.equal( $.trimLeft( ' foo bar ' ), 'foo bar ', 'trimLeft' );
15 assert.equal( $.trimRight( ' foo bar ' ), ' foo bar', 'trimRight' );
16 assert.equal( $.ucFirst( 'foo' ), 'Foo', 'ucFirst' );
18 assert.equal( $.escapeRE( '<!-- ([{+mW+}]) $^|?>' ),
19 '<!\\-\\- \\(\\[\\{\\+mW\\+\\}\\]\\) \\$\\^\\|\\?>', 'escapeRE - Escape specials' );
20 assert.equal( $.escapeRE( 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' ),
21 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'escapeRE - Leave uppercase alone' );
22 assert.equal( $.escapeRE( 'abcdefghijklmnopqrstuvwxyz' ),
23 'abcdefghijklmnopqrstuvwxyz', 'escapeRE - Leave lowercase alone' );
24 assert.equal( $.escapeRE( '0123456789' ), '0123456789', 'escapeRE - Leave numbers alone' );
27 QUnit.test( 'isDomElement', 6, function ( assert ) {
28 assert.strictEqual( $.isDomElement( document.createElement( 'div' ) ), true,
29 'isDomElement: HTMLElement' );
30 assert.strictEqual( $.isDomElement( document.createTextNode( '' ) ), true,
31 'isDomElement: TextNode' );
32 assert.strictEqual( $.isDomElement( null ), false,
33 'isDomElement: null' );
34 assert.strictEqual( $.isDomElement( document.getElementsByTagName( 'div' ) ), false,
35 'isDomElement: NodeList' );
36 assert.strictEqual( $.isDomElement( $( 'div' ) ), false,
37 'isDomElement: jQuery' );
38 assert.strictEqual( $.isDomElement( { foo: 1 } ), false,
39 'isDomElement: Plain Object' );
42 QUnit.test( 'isEmpty', 7, function ( assert ) {
43 assert.strictEqual( $.isEmpty( 'string' ), false, 'isEmpty: "string"' );
44 assert.strictEqual( $.isEmpty( '0' ), true, 'isEmpty: "0"' );
45 assert.strictEqual( $.isEmpty( '' ), true, 'isEmpty: ""' );
46 assert.strictEqual( $.isEmpty( 1 ), false, 'isEmpty: 1' );
47 assert.strictEqual( $.isEmpty( [] ), true, 'isEmpty: []' );
48 assert.strictEqual( $.isEmpty( {} ), true, 'isEmpty: {}' );
50 // Documented behavior
51 assert.strictEqual( $.isEmpty( { length: 0 } ), true, 'isEmpty: { length: 0 }' );
54 QUnit.test( 'Comparison functions', 5, function ( assert ) {
55 assert.ok( $.compareArray( [ 0, 'a', [], [ 2, 'b' ] ], [ 0, 'a', [], [ 2, 'b' ] ] ),
56 'compareArray: Two deep arrays that are excactly the same' );
57 assert.ok( !$.compareArray( [ 1 ], [ 2 ] ), 'compareArray: Two different arrays (false)' );
59 assert.ok( $.compareObject( {}, {} ), 'compareObject: Two empty objects' );
60 assert.ok( $.compareObject( { foo: 1 }, { foo: 1 } ), 'compareObject: Two the same objects' );
61 assert.ok( !$.compareObject( { bar: true }, { baz: false } ),
62 'compareObject: Two different objects (false)' );