From ea9d093f0dad37b34c0c8707874e8f41ee84128c Mon Sep 17 00:00:00 2001 From: John Tantalo Date: Tue, 27 Nov 2012 19:50:35 -0800 Subject: [PATCH 1/2] in strict mode, `this` is undefined --- ua-parser.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ua-parser.js b/ua-parser.js index 8347679..153344c 100644 --- a/ua-parser.js +++ b/ua-parser.js @@ -358,7 +358,7 @@ }; // check whether script is running inside node.js export as module - if (typeof exports !== 'undefined' && this.toString() !== '[object DOMWindow]') { + if (typeof exports !== 'undefined' && (!this || this.toString() !== '[object DOMWindow]')) { if (typeof module !== 'undefined' && module.exports) { exports = module.exports = UAParser; } From 08c7a84407b4f35c48d247122fef663fa959c5c1 Mon Sep 17 00:00:00 2001 From: John Tantalo Date: Tue, 27 Nov 2012 20:44:37 -0800 Subject: [PATCH 2/2] added simple test case (mocha) --- .gitignore | 1 + package.json | 6 ++++++ test.js | 10 ++++++++++ 3 files changed, 17 insertions(+) create mode 100644 .gitignore create mode 100644 test.js diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c2658d7 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +node_modules/ diff --git a/package.json b/package.json index d25a2a1..a098b3b 100644 --- a/package.json +++ b/package.json @@ -17,6 +17,12 @@ "Faisal Salman " ], "main": "ua-parser", + "scripts": { + "test": "./node_modules/mocha/bin/mocha" + }, + "devDependencies": { + "mocha": ">= 1.7.1" + }, "repositories": [ { "type": "git", diff --git a/test.js b/test.js new file mode 100644 index 0000000..18c72f9 --- /dev/null +++ b/test.js @@ -0,0 +1,10 @@ +var assert = require("assert"); +var UAParser = require("./ua-parser"); + +describe('getDevice', function () { + it('should return the model', function () { + var parser = new UAParser('Mozilla/5.0 (PlayBook; U; RIM Tablet OS 1.0.0; en-US) AppleWebKit/534.11 (KHTML, like Gecko) Version/7.1.0.7 Safari/534.11'); + var device = parser.getDevice(); + assert.equal(device.model, "PlayBook"); + }); +});