Skip to content

Commit

Permalink
fix lint
Browse files Browse the repository at this point in the history
  • Loading branch information
vraja-pro committed Dec 31, 2024
1 parent ce4898f commit e1dddc2
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 29 deletions.
2 changes: 1 addition & 1 deletion packages/helpers/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const config = {
"**/*Test.[jt]s",
],
testEnvironmentOptions: {
url: "http://localhost"
url: "http://localhost",
},
setupFilesAfterEnv: [ "<rootDir>/tools/jest/setupTests.js" ],
collectCoverageFrom: [
Expand Down
56 changes: 28 additions & 28 deletions packages/helpers/tests/i18nCreateInterpolateElementTest.js
Original file line number Diff line number Diff line change
@@ -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: <span>world</span> };
const interpolatedElement = <span>Hello world</span>;

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: <span>world</span> };

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 );
} );
} );

0 comments on commit e1dddc2

Please sign in to comment.