From 7a343c52163871b679acd0e5495f62c0f12bb79a Mon Sep 17 00:00:00 2001 From: Opeyemi Ibrahim Date: Fri, 11 Oct 2024 12:45:01 +0100 Subject: [PATCH] Improve test coverage --- test/BeaconLcp.test.js | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/test/BeaconLcp.test.js b/test/BeaconLcp.test.js index 0417075..af13966 100644 --- a/test/BeaconLcp.test.js +++ b/test/BeaconLcp.test.js @@ -1,6 +1,7 @@ import assert from 'assert'; import BeaconLcp from '../src/BeaconLcp.js'; import node_fetch from 'node-fetch'; +import sinon from 'sinon'; global.fetch = node_fetch; describe('BeaconManager', function() { @@ -12,6 +13,29 @@ describe('BeaconManager', function() { mockLogger = { logMessage: function(message) {} }; beacon = new BeaconLcp(config, mockLogger); + + global.window = {}; + global.document = {}; + + global.window.getComputedStyle = sinon.stub().returns({ + getPropertyValue: sinon.stub().returns('none'), + }); + + global.getComputedStyle = (element, pseudoElement) => { + return { + getPropertyValue: (prop) => { + if (prop === "background-image") { + return "none"; + } + return ""; + } + }; + }; + }); + + afterEach(function () { + sinon.restore(); + delete global.window; }); describe('#constructor()', function() { @@ -60,4 +84,16 @@ describe('BeaconManager', function() { assert.strictEqual(beacon.performanceImages.length, 0); }); }); + + describe('#_getElementInfo()', function() { + it('should return null when there are no valid background images', function() { + const element = { + nodeName: 'div' + }; + + const elementInfo = beacon._getElementInfo(element); + + assert.strictEqual(elementInfo, null); + }); + }); });