diff --git a/packages/helpers/jest.config.js b/packages/helpers/jest.config.js index 24441cfba98..17a2683f562 100644 --- a/packages/helpers/jest.config.js +++ b/packages/helpers/jest.config.js @@ -4,7 +4,7 @@ const config = { "**/*Test.[jt]s", ], testEnvironmentOptions: { - url: "http://localhost" + url: "http://localhost", }, setupFilesAfterEnv: [ "/tools/jest/setupTests.js" ], collectCoverageFrom: [ diff --git a/packages/helpers/tests/i18nCreateInterpolateElementTest.js b/packages/helpers/tests/i18nCreateInterpolateElementTest.js index a4a685d36a3..71cd83eb843 100644 --- a/packages/helpers/tests/i18nCreateInterpolateElementTest.js +++ b/packages/helpers/tests/i18nCreateInterpolateElementTest.js @@ -1,52 +1,52 @@ -import React from 'react'; +import React from "react"; import { i18nCreateInterpolateElement } from "../src/i18n-create-interpolate-element"; import { createInterpolateElement } from "@wordpress/element"; import { sprintf } from "@wordpress/i18n"; -jest.mock("@wordpress/element", () => ({ +jest.mock( "@wordpress/element", () => ( { createInterpolateElement: jest.fn(), -})); +} ) ); -jest.mock("@wordpress/i18n", () => ({ +jest.mock( "@wordpress/i18n", () => ( { sprintf: jest.fn(), -})); +} ) ); -describe("i18nCreateInterpolateElement", () => { - beforeEach(() => { +describe( "i18nCreateInterpolateElement", () => { + beforeEach( () => { jest.clearAllMocks(); - }); + } ); - it("should return interpolated element when no error occurs", () => { + it( "should return interpolated element when no error occurs", () => { const translatedString = "Hello %s"; - const args = ["world"]; + const args = [ "world" ]; const conversionMap = { world: world }; const interpolatedElement = Hello world; - sprintf.mockReturnValue("Hello world"); - createInterpolateElement.mockReturnValue(interpolatedElement); + sprintf.mockReturnValue( "Hello world" ); + createInterpolateElement.mockReturnValue( interpolatedElement ); - const result = i18nCreateInterpolateElement(translatedString, args, conversionMap); + const result = i18nCreateInterpolateElement( translatedString, args, conversionMap ); - expect(sprintf).toHaveBeenCalledWith(translatedString, ...args); - expect(createInterpolateElement).toHaveBeenCalledWith("Hello world", conversionMap); - expect(result).toBe(interpolatedElement); - }); + expect( sprintf ).toHaveBeenCalledWith( translatedString, ...args ); + expect( createInterpolateElement ).toHaveBeenCalledWith( "Hello world", conversionMap ); + expect( result ).toBe( interpolatedElement ); + } ); - it("should return translated string and log error when an error occurs", () => { + it( "should return translated string and log error when an error occurs", () => { const translatedString = "Hello %s"; - const args = ["world"]; + const args = [ "world" ]; const conversionMap = { world: world }; - sprintf.mockImplementation(() => { - throw new Error("Test error"); - }); + sprintf.mockImplementation( () => { + throw new Error( "Test error" ); + } ); console.error = jest.fn(); - const result = i18nCreateInterpolateElement(translatedString, args, conversionMap); + const result = i18nCreateInterpolateElement( translatedString, args, conversionMap ); - expect(sprintf).toHaveBeenCalledWith(translatedString, ...args); - expect(console.error).toHaveBeenCalledWith("Error in translation for:", translatedString); - expect(result).toBe(translatedString); - }); -}); + expect( sprintf ).toHaveBeenCalledWith( translatedString, ...args ); + expect( console.error ).toHaveBeenCalledWith( "Error in translation for:", translatedString ); + expect( result ).toBe( translatedString ); + } ); +} );