chicago
Version:
A front-end JavaScript library for user-interface developers.
218 lines (166 loc) • 5.98 kB
JavaScript
describe('Chicago.Utilities', function() {
var _c,
should;
if( typeof require === 'function' ) {
require('mocha-jsdom')();
var should = require('should');
}
before(function() {
if( typeof require !== 'undefined' ) {
global.window.jQuery = require('jquery');
_c = require('../../../dist/Chicago.js');
} else {
_c = window.Chicago;
}
});
describe('#properties', function() {
it('Property `now` exists', function() {
_c.utils.should.have.property( 'now' );
});
it('Property `debounce` exists', function() {
_c.utils.should.have.property( 'debounce' );
});
it('Property `toCamelCase` exists', function() {
_c.utils.should.have.property( 'toCamelCase' );
});
it('Property `is` exists', function() {
_c.utils.should.have.property( 'is' );
});
it('Property `uid` exists', function() {
_c.utils.should.have.property( 'uid' );
});
it('Property `watch` exists', function() {
_c.utils.should.have.property( 'watch' );
});
it('Property `unwatch` exists', function() {
_c.utils.should.have.property( 'unwatch' );
});
it('Property `getCSSValue` exists', function() {
_c.utils.should.have.property( 'getCSSValue' );
});
it('Property `stringToMilliseconds` exists', function() {
_c.utils.should.have.property( 'stringToMilliseconds' );
});
});
describe('#methods', function() {
it('Method `now` returns integer', function() {
(typeof _c.utils.now() === 'number').should.be.true;
});
it('Method `now` returns current time', function() {
var fn = Date.now || function() {
return new Date().getTime();
};
(_c.utils.now() === fn()).should.be.true;
});
// it('Method `debounce` NEEDS TEST', function() {
// (true).should.not.be.true;
// });
it('Method `toCamelCase` returns string', function() {
(typeof _c.utils.toCamelCase('new string') === 'string').should.be.true;
});
it('Method `toCamelCase` returns valid string', function() {
var input = 'test string',
expected = 'testString';
_c.utils.toCamelCase(input).should.equal(expected);
});
it('Method `is.undefined` returns true', function() {
_c.utils.is.undefined(undefined).should.be.true;
});
it('Method `is.undefined` returns false', function() {
_c.utils.is.undefined('string').should.not.be.true;
});
it('Method `is.string` returns true', function() {
_c.utils.is.string('string').should.be.true;
});
it('Method `is.string` returns false', function() {
_c.utils.is.string(1234).should.not.be.true;
});
it('Method `is.numeric` returns true with integer', function() {
_c.utils.is.numeric(1234).should.be.true;
});
it('Method `is.numeric` returns true with float', function() {
_c.utils.is.numeric(12.34).should.be.true;
});
it('Method `is.numeric` returns true with string', function() {
_c.utils.is.numeric('1234').should.be.true;
});
it('Method `is.numeric` returns false', function() {
_c.utils.is.numeric({ one : 1 }).should.not.be.true;
});
it('Method `is.integer` returns true', function() {
_c.utils.is.integer(1234).should.be.true;
});
it('Method `is.integer` returns false', function() {
_c.utils.is.integer('string').should.not.be.true;
});
it('Method `is.float` returns true', function() {
_c.utils.is.float(12.34).should.be.true;
});
it('Method `is.float` returns false', function() {
_c.utils.is.float(1234).should.not.be.true;
});
it('Method `is.date` returns true with Date object', function() {
_c.utils.is.date(new Date()).should.be.true;
});
it('Method `is.date` returns true with String', function() {
_c.utils.is.date('January 1, 2015').should.be.true;
});
it('Method `is.date` returns false', function() {
_c.utils.is.date('new string').should.not.be.true;
});
it('Method `is.jQueryObject` returns true', function() {
_c.utils.is.jQueryObject(_c.$('body')).should.be.true;
});
it('Method `is.jQueryObject` returns false', function() {
_c.utils.is.jQueryObject({ one : 1 }).should.not.be.true;
});
it('Method `is.function` returns true', function() {
_c.utils.is.function(function() {}).should.be.true;
});
it('Method `is.function` returns false', function() {
_c.utils.is.function('string').should.not.be.true;
});
it('Method `is.array` returns true', function() {
_c.utils.is.array([1, 2, 3]).should.be.true;
});
it('Method `is.array` returns false', function() {
_c.utils.is.array({ one : 1 }).should.not.be.true;
});
it('Method `is.object` returns true', function() {
_c.utils.is.object({ one : 1 }).should.be.true;
});
it('Method `is.object` returns false', function() {
_c.utils.is.object([1, 2, 3]).should.not.be.true;
});
// it('Method `is.inView` NEEDS TEST', function() {
// (true).should.not.be.true;
// });
it('Method `uid` return string', function() {
_c.utils.uid().should.be.type('string');
});
it('Method `getCSSValue` returns string', function() {
_c.utils.getCSSValue( _c.$body, 'background-color' ).should.be.type('string');
});
it('Method `getCSSValue` returns integer', function() {
_c.utils.getCSSValue( _c.$body, 'width' ).should.be.type('number');
});
it('Method `getCSSValue` returns float', function() {
_c.$body.append('<div class="tmp" />');
_c.$('.tmp').css('opacity', 0.5);
var val = _c.utils.getCSSValue( _c.$('.tmp'), 'opacity' );
_c.utils.is.float( val ).should.be.true;
});
it('Method `stringToMilliseconds` valid with string', function() {
var val = _c.utils.stringToMilliseconds( '0.5s' );
_c.utils.is.integer( val ).should.be.true;
});
it('Method `stringToMilliseconds` valid with float', function() {
var val = _c.utils.stringToMilliseconds( 0.5 );
_c.utils.is.integer( val ).should.be.true;
});
it('Method `stringToMilliseconds` returns valid value', function() {
var val = _c.utils.stringToMilliseconds( '0.5s' );
val.should.equal( 500 );
});
});
});