From 70acb60537c28c896f7e50e0a49776a7f0df9471 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 21 Nov 2025 21:52:03 +0000 Subject: [PATCH] Add comprehensive tests for named exports Co-authored-by: naorpeled <6171622+naorpeled@users.noreply.github.com> --- test/unit/bowser.js | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/test/unit/bowser.js b/test/unit/bowser.js index 6889898..f568893 100644 --- a/test/unit/bowser.js +++ b/test/unit/bowser.js @@ -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); +});