mirror of
https://github.com/lancedikson/bowser
synced 2025-12-04 21:52:14 +00:00
Add comprehensive tests for named exports
Co-authored-by: naorpeled <6171622+naorpeled@users.noreply.github.com>
This commit is contained in:
parent
b0877ffd5f
commit
70acb60537
@ -23,10 +23,31 @@ test('Named export getParser works like Bowser.getParser', (t) => {
|
||||
t.deepEqual(namedExportParser.getResult(), browser.getResult());
|
||||
});
|
||||
|
||||
test('Named export getParser with skipParsing parameter', (t) => {
|
||||
const parserWithSkip = getParser(UA, true);
|
||||
t.truthy(parserWithSkip instanceof Parser);
|
||||
// With skipParsing=true, the result should be undefined until we explicitly parse
|
||||
t.deepEqual(parserWithSkip.getResult(), Bowser.getParser(UA, true).getResult());
|
||||
});
|
||||
|
||||
test('Named export getParser throws error for invalid UA', (t) => {
|
||||
t.throws(() => getParser(undefined), { message: 'UserAgent should be a string' });
|
||||
t.throws(() => getParser(123), { message: 'UserAgent should be a string' });
|
||||
t.throws(() => getParser(null), { message: 'UserAgent should be a string' });
|
||||
t.throws(() => getParser({}), { message: 'UserAgent should be a string' });
|
||||
});
|
||||
|
||||
test('Named export parse works like Bowser.parse', (t) => {
|
||||
t.deepEqual(parse(UA), Bowser.parse(UA));
|
||||
});
|
||||
|
||||
test('Named export parse produces consistent results', (t) => {
|
||||
const result1 = parse(UA);
|
||||
const result2 = parse(UA);
|
||||
t.deepEqual(result1, result2);
|
||||
t.deepEqual(result1, Bowser.parse(UA));
|
||||
});
|
||||
|
||||
test('Named exports of constants are available', (t) => {
|
||||
t.truthy(BROWSER_MAP);
|
||||
t.truthy(ENGINE_MAP);
|
||||
@ -37,3 +58,22 @@ test('Named exports of constants are available', (t) => {
|
||||
t.is(OS_MAP, Bowser.OS_MAP);
|
||||
t.is(PLATFORMS_MAP, Bowser.PLATFORMS_MAP);
|
||||
});
|
||||
|
||||
test('Named exports constants are objects with expected structure', (t) => {
|
||||
t.is(typeof BROWSER_MAP, 'object');
|
||||
t.is(typeof ENGINE_MAP, 'object');
|
||||
t.is(typeof OS_MAP, 'object');
|
||||
t.is(typeof PLATFORMS_MAP, 'object');
|
||||
});
|
||||
|
||||
test('All named exports work together', (t) => {
|
||||
// Test that we can use multiple named exports in the same scope
|
||||
const result = parse(UA);
|
||||
const parser = getParser(UA);
|
||||
|
||||
t.deepEqual(result, parser.getResult());
|
||||
t.truthy(BROWSER_MAP);
|
||||
t.truthy(ENGINE_MAP);
|
||||
t.truthy(OS_MAP);
|
||||
t.truthy(PLATFORMS_MAP);
|
||||
});
|
||||
|
||||
Loading…
Reference in New Issue
Block a user