Skip to content
This repository has been archived by the owner on Feb 12, 2022. It is now read-only.

Commit

Permalink
add tests for utilities object and cleanup method
Browse files Browse the repository at this point in the history
  • Loading branch information
swilliamset committed Jun 10, 2017
1 parent 9b12717 commit 0a30d81
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
1 change: 1 addition & 0 deletions test/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,5 @@ define(function testWrapper (require) {
require('./test/picker-test');
require('./test/tree-test');
require('./test/wizard-test');
require('./test/utilities-test');
});
41 changes: 41 additions & 0 deletions test/utilities-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
define( function utilitiesTestModule(require) {
var QUnit = require('qunit');
var $ = require('jquery');

require('fuelux/utilities');

QUnit.module( 'Fuel UX Utilities', function utilitiesTests() {
QUnit.test( 'should be defined on jquery object', function utilitiesObjectDefinedTest( assert ) {
assert.equal(typeof $().utilities, 'object', 'utilities object is defined' );
});

QUnit.module( 'cleanInput Method', {
beforeEach: function beforeEachUtilitiesCleanInputTests() {
this.utilities = $().utilities;
this.cleanInput = this.utilities.cleanInput;
}
}, function utilitiesCleanInputTests() {
QUnit.test( 'should be defined on utilities object', function cleanInputMethodDefinedTest( assert ) {
assert.equal(typeof this.utilities.cleanInput, 'function', 'cleanInput function is defined' );
});

QUnit.test( 'should encode strings', function cleanInputMethodEncodeTest( assert ) {
var dirtyString = '<script>';
var cleanString = '&lt;script&gt;';
assert.equal(this.cleanInput(dirtyString), cleanString, 'string should be encoded' );
});

QUnit.test( 'should not double encode strings', function cleanInputMethodEncodeTest( assert ) {
var variants = [
{dirtyString: '&lt;&gt;', cleanString: '&lt;&gt;'},
{dirtyString: '&lt;script&gt;', cleanString: '&lt;script&gt;'},
{dirtyString: '<&lt;&gt;>', cleanString: '&lt;&lt;&gt;&gt;'}
];

variants.forEach(function forEachDoubleEncodeVariant(variant, index) {
assert.equal(this.cleanInput(variant.dirtyString), variant.cleanString, 'variant ' + (index + 1) + ' string should be encoded' );
}, this);
});
});
});
});

0 comments on commit 0a30d81

Please sign in to comment.