Skip to content

Commit

Permalink
Test: fixed tests to ensure queue is cleared before each test is run.
Browse files Browse the repository at this point in the history
  • Loading branch information
Krishna Kapadia committed Feb 9, 2021
1 parent 7bcd92a commit 692fbee
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions src/raygun.rum/core-web-vitals.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,17 @@
require('./core-web-vitals');

describe("core-web-vitals", () => {
const CoreWebVitals = window.raygunCoreWebVitalFactory({ webVitals: null }), queue = [];
let CoreWebVitals = window.raygunCoreWebVitalFactory({ webVitals: null }), queue = [];
CoreWebVitals.attach(e => queue.push(e));

describe("handler is called", () => {
CoreWebVitals.handler({ name: "FID", value: "1" });

beforeEach(() => {
queue = [];
});

describe("handler is called", () => {
it("creates the appropriate payload", () => {
CoreWebVitals.handler({ name: "FID", value: "1" });

expect(queue.pop()).toEqual({
url: "FID",
timing: {
Expand All @@ -18,15 +22,15 @@ describe("core-web-vitals", () => {
}
});
});

});

describe("event reports long metric value", () => {
CoreWebVitals.handler({ name: "FID", value: "0.14589" });

it('value is rounded to 3dp', () => {
CoreWebVitals.handler({ name: "FID", value: 0.14589 });

var res = queue.pop();
expect(res.timing.du).toBe("0.146");
expect(res.timing.du).toBe('0.146');
});
});
});

0 comments on commit 692fbee

Please sign in to comment.