From 0ef1b75f310f11b619612a75b1da35bee47ae150 Mon Sep 17 00:00:00 2001 From: Leon Bubova Date: Mon, 1 Aug 2022 16:20:57 +0200 Subject: [PATCH] add failing test for buggy behaviour in a separate test case and skip it until fixed --- .../src/__snapshots__/utils.spec.js.snap | 2 ++ Extensions/combined/src/utils.spec.js | 22 ++++++++++++++++--- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/Extensions/combined/src/__snapshots__/utils.spec.js.snap b/Extensions/combined/src/__snapshots__/utils.spec.js.snap index 51fa0fef..7c6616cc 100644 --- a/Extensions/combined/src/__snapshots__/utils.spec.js.snap +++ b/Extensions/combined/src/__snapshots__/utils.spec.js.snap @@ -6,6 +6,8 @@ exports[`getNumberFormatter should return a correct formatter when using chrome exports[`getNumberFormatter should return a correct formatter when using firefox 1`] = `NumberFormat {}`; +exports[`getNumberFormatter should return a correct formatter when using the URL locale (possibly buggy) 1`] = `NumberFormat {}`; + exports[`getNumberFormatter should return a correct formatter when using the URL locale 1`] = `NumberFormat {}`; exports[`getNumberFormatter should return a correct formatter whith standard option 1`] = `NumberFormat {}`; diff --git a/Extensions/combined/src/utils.spec.js b/Extensions/combined/src/utils.spec.js index 641da844..de50338f 100644 --- a/Extensions/combined/src/utils.spec.js +++ b/Extensions/combined/src/utils.spec.js @@ -100,7 +100,7 @@ describe("getNumberFormatter", () => { expect(getNumberFormatter()).toMatchSnapshot(); }); - it("should return a correct formatter when using the URL locale", () => { + it("should return a correct formatter when using the URL locale (possibly buggy)", () => { // Disclaimer: The case we are testing here is actually not correct and // am almost sure I found a bug in the actual implementation of // getNumberFormatter(). As I am currently writing acceptance tests only @@ -109,6 +109,8 @@ describe("getNumberFormatter", () => { // for now and document how we should actually be testing down below. // The reason why this bug is not causing faulty behaviour is, that we // have a fallback for it, that is always triggered. + + // This is how we make the test go green: Object.defineProperty(document.documentElement, "lang", { value: null, configurable: true, @@ -119,13 +121,27 @@ describe("getNumberFormatter", () => { }); const mockedNode = document.createElement("link"); - // This is how we make the test go green: mockedNode.setAttribute( "href", "https://www.youtube.com/opensearch?locale=en" ); + + document.querySelectorAll = jest.fn().mockReturnValue([mockedNode]); + expect(getNumberFormatter()).toMatchSnapshot(); + }); + + it.skip("should return a correct formatter when using the URL locale", () => { // But we actually want to test like so, which is the correct value of the locale attribute: - // mockedNode.setAttribute("href", "https://www.youtube.com/opensearch?locale=en_US"); + Object.defineProperty(document.documentElement, "lang", { + value: null, + configurable: true, + }); + Object.defineProperty(navigator, "language", { + value: null, + configurable: true, + }); + const mockedNode = document.createElement("link"); + mockedNode.setAttribute("href", "https://www.youtube.com/opensearch?locale=en_US"); document.querySelectorAll = jest.fn().mockReturnValue([mockedNode]); expect(getNumberFormatter()).toMatchSnapshot();