mirror of
https://github.com/lancedikson/bowser
synced 2024-10-27 20:34:22 +00:00
Fix Bowser constructor, add some tests
This commit is contained in:
parent
98007768b4
commit
e7e6abff8b
@ -17,21 +17,22 @@ import Parser from './parser';
|
|||||||
class Bowser {
|
class Bowser {
|
||||||
/**
|
/**
|
||||||
* Creates an object that parses UA
|
* Creates an object that parses UA
|
||||||
* @param UA
|
* @param {String} UA — UserAgent string
|
||||||
|
* @param {Boolean} [skipParsing=false] — same as skipParsing for Parser
|
||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
* const bowser = new Bowser(window.navigator.userAgent);
|
* const bowser = new Bowser(window.navigator.userAgent);
|
||||||
* bowser.getBrowser()
|
* bowser.getBrowser()
|
||||||
*/
|
*/
|
||||||
constructor(UA) {
|
constructor(UA, skipParsing=false) {
|
||||||
if (!UA) {
|
if (!UA) {
|
||||||
throw new Error('UserAgent is not defined');
|
throw new Error('UserAgent is not defined');
|
||||||
}
|
}
|
||||||
return new Parser(UA);
|
return new Parser(UA, skipParsing);
|
||||||
}
|
}
|
||||||
|
|
||||||
static parse(UA) {
|
static parse(UA) {
|
||||||
return (new this.constructor(UA)).getResult();
|
return (new Bowser(UA)).getResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
18
test/unit/bowser.js
Normal file
18
test/unit/bowser.js
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
import test from 'ava';
|
||||||
|
import Bowser from '../../src/bowser';
|
||||||
|
import Parser from '../../src/parser';
|
||||||
|
|
||||||
|
const UA = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36 OPR/43.0.2442.1165';
|
||||||
|
const browser = new Bowser(UA);
|
||||||
|
|
||||||
|
test('Bowser`s constructor returns a Parser instance', (t) => {
|
||||||
|
t.truthy(browser instanceof Parser);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Bowser`s constructor fails if UA is empty', (t) => {
|
||||||
|
t.throws(() => (new Bowser()));
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Bowser.parse parses UA and returns result', (t) => {
|
||||||
|
t.deepEqual(Bowser.parse(UA), browser.getResult());
|
||||||
|
});
|
Loading…
Reference in New Issue
Block a user