Skip to content

Commit

Permalink
Improve test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
Khadreal committed Oct 11, 2024
1 parent 4b5bd67 commit 7a343c5
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions test/BeaconLcp.test.js
Original file line number Diff line number Diff line change
@@ -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() {
Expand All @@ -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() {
Expand Down Expand Up @@ -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);
});
});
});

0 comments on commit 7a343c5

Please sign in to comment.