Skip to content

Commit

Permalink
Remove type checks, tighten up tests toBe
Browse files Browse the repository at this point in the history
  • Loading branch information
iamdustan committed Dec 6, 2012
1 parent 8e894f2 commit e021d55
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 13 deletions.
6 changes: 0 additions & 6 deletions src/tools.js
Expand Up @@ -349,10 +349,6 @@ define([], function() {
* @returns {String} unit * @returns {String} unit
*/ */
extractUnit: function (any) { extractUnit: function (any) {
if (typeof any === 'undefined' || typeof any === 'number') {
return '';
}

// make sure it's a string and remove trailing whitespace // make sure it's a string and remove trailing whitespace
var unit = String(any).replace(/\s+$/, ''); var unit = String(any).replace(/\s+$/, '');
// returns extracted unit or empty string // returns extracted unit or empty string
Expand Down Expand Up @@ -381,8 +377,6 @@ define([], function() {
radians = amount * PI / 200; break; radians = amount * PI / 200; break;
case 'turn': case 'turn':
radians = amount * 2 * PI; break; radians = amount * 2 * PI; break;
default:
radians = 0;
} }


return radians; return radians;
Expand Down
14 changes: 7 additions & 7 deletions test/tools-spec.js
Expand Up @@ -293,49 +293,49 @@ define([
var returned = extractUnit('9deg'); var returned = extractUnit('9deg');
var expected = 'deg'; var expected = 'deg';


expect(returned).toEqual(expected); expect(returned).toBe(expected);
}); });


it('should work with negative numbers', function() { it('should work with negative numbers', function() {
var returned = extractUnit('-741232grad'); var returned = extractUnit('-741232grad');
var expected = 'grad'; var expected = 'grad';


expect(returned).toEqual(expected); expect(returned).toBe(expected);
}); });


it('should work with trailing whitespace', function() { it('should work with trailing whitespace', function() {
var returned = extractUnit('-741232grad '); var returned = extractUnit('-741232grad ');
var expected = 'grad'; var expected = 'grad';


expect(returned).toEqual(expected); expect(returned).toBe(expected);
}); });


it('should work with leading whitespace', function() { it('should work with leading whitespace', function() {
var returned = extractUnit('-741232 grad '); var returned = extractUnit('-741232 grad ');
var expected = 'grad'; var expected = 'grad';


expect(returned).toEqual(expected); expect(returned).toBe(expected);
}); });


it('should return an empty string in case of a number', function () { it('should return an empty string in case of a number', function () {
var returned = extractUnit(7531); var returned = extractUnit(7531);
var expected = ''; var expected = '';


expect(returned).toEqual(expected); expect(returned).toBe(expected);
}); });


it('should return the string when given an array', function () { it('should return the string when given an array', function () {
var returned = extractUnit(['50s']); var returned = extractUnit(['50s']);
var expected = 's'; var expected = 's';


expect(returned).toEqual(expected); expect(returned).toBe(expected);
}); });


it('should work with percentages', function () { it('should work with percentages', function () {
var returned = extractUnit('50%'); var returned = extractUnit('50%');
var expected = '%'; var expected = '%';


expect(returned).toEqual(expected); expect(returned).toBe(expected);
}); });
}); });


Expand Down

0 comments on commit e021d55

Please sign in to comment.