Skip to content

Commit 1747d68

Browse files
committed
mocha unit tests for utils.js
1 parent 4276b28 commit 1747d68

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed

lib/utils.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,12 @@ var uuid = function uuidGenerator() {
2626
};
2727

2828
var browserString = function browserString(config) {
29-
return config.os + ' ' + config.os_version + ', ' + (config.browser == 'ie' ? 'IE' : titleCase(config.browser || config.device)) + ' ' + (config.browser_version || config.device);
29+
var os_details = config.os + ' ' + config.os_version;
30+
if (config.browser) {
31+
return os_details + ', ' + (config.browser == 'ie' ? 'Internet Explorer' : titleCase(config.browser)) + ' ' + config.browser_version;
32+
} else {
33+
return os_details + (config.device ? (', ' + config.device) : "");
34+
}
3035
};
3136

3237
var objectSize = function objectSize(obj) {

tests/unit/utils_spec.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
var utils = require("./../../lib/utils");
2+
var assert = require("assert");
3+
4+
describe('Utilities', function(){
5+
it('should titlize all strings properly', function(){
6+
assert.equal("Hello", utils.titleCase("hello"));
7+
assert.equal("Are You Serious?", utils.titleCase("are you serious?"));
8+
});
9+
10+
it('should generate 32 char uuid', function(){
11+
assert.equal(5, utils.uuid().split("-").length);
12+
assert.equal(32 + 4, utils.uuid().length);
13+
});
14+
15+
it('should generate random uuid always', function(){
16+
assert.notEqual(utils.uuid(), utils.uuid());
17+
assert.notEqual(utils.uuid(), utils.uuid());
18+
});
19+
20+
it('should generate proper browser string for config', function(){
21+
var chrome_mac = {os: "OS X", os_version: "Mavericks", "browser": "chrome", "browser_version": "latest"};
22+
var chrome_windows = {os: "Windows", os_version: "XP", "browser": "chrome", "browser_version": "latest"};
23+
// var safari_mac = {os: "OS X", os_version: "Mountain Lion", "browser": "safari", "browser_version": "6.1"};
24+
var ie_windows = {os: "Windows", os_version: "7", "browser": "ie", "browser_version": "9.0"};
25+
var iOS = {os: "iOS", os_version: "6.0", device: "iPhone 5"};
26+
var androidConfig = {os: "android", os_version: "4.1"};
27+
28+
assert.equal("OS X Mavericks, Chrome latest", utils.browserString(chrome_mac));
29+
assert.equal("Windows XP, Chrome latest", utils.browserString(chrome_windows));
30+
assert.equal("Windows 7, Internet Explorer 9.0", utils.browserString(ie_windows));
31+
assert.equal("iOS 6.0, iPhone 5", utils.browserString(iOS));
32+
assert.equal("android 4.1", utils.browserString(androidConfig));
33+
});
34+
35+
it('should return number of keys for this object', function(){
36+
assert.equal(0, utils.objectSize({}));
37+
assert.equal(1, utils.objectSize({a: 2}));
38+
});
39+
});

0 commit comments

Comments
 (0)