Skip to content

Commit

Permalink
fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
aliraza556 authored and gabrielmfern committed Sep 24, 2024
1 parent 2b43917 commit d8c80a8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 16 deletions.
23 changes: 12 additions & 11 deletions packages/font/src/font.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Font } from "./index";
describe("<Font> component", () => {
it("renders with default props", async () => {
const html = await render(
<Font fallbackFontFamily="Helvetica" fontFamily="Arial" />,
<Font fallbackFontFamily="Helvetica" fontFamily="Arial" />
);

expect(html).toContain("font-style: normal;");
Expand All @@ -23,26 +23,26 @@ describe("<Font> component", () => {
fallbackFontFamily="Helvetica"
fontFamily="Example"
webFont={webFont}
/>,
/>
);

expect(html).toContain("font-family: 'Example';");
expect(html).toContain(
`src: url(${webFont.url}) format('${webFont.format}');`,
`src: url(${webFont.url}) format('${webFont.format}');`
);
});

it("renders with multiple fallback fonts", async () => {
const html = await render(
<Font fallbackFontFamily={["Helvetica", "Verdana"]} fontFamily="Arial" />,
<Font fallbackFontFamily={["Helvetica", "Verdana"]} fontFamily="Arial" />
);

expect(html).toContain("font-family: 'Arial', Helvetica, Verdana;");
});

it("renders correctly", async () => {
const actualOutput = await render(
<Font fallbackFontFamily="Verdana" fontFamily="Roboto" />,
<Font fallbackFontFamily="Verdana" fontFamily="Roboto" />
);
expect(actualOutput).toMatchSnapshot();
});
Expand All @@ -52,18 +52,19 @@ describe("<Font> component", () => {
url: '"http://example.com/font.woff"',
format: "woff",
} as const;

const html = await render(
<Font
fallbackFontFamily={["Helvetica Neue", "Arial"]}
fontFamily="My 'Custom' Font"
webFont={webFont}
/>,
/>
);

expect(html).toContain("font-family: 'My \\'Custom\\' Font';");
expect(html).toContain("Helvetica Neue, Arial");
expect(html).toContain('src: url("http://example.com/font.woff") format(\'woff\');');
expect(html).toContain(
'src: url(\\"http://example.com/font.woff\\") format(\'woff\');'
);
});

});
});
10 changes: 5 additions & 5 deletions packages/font/src/font.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,11 @@ export const Font: React.FC<Readonly<FontProps>> = ({
* {
font-family: '${fontFamily.replace(/'/g, "\\'")}', ${
Array.isArray(fallbackFontFamily)
? fallbackFontFamily.map(font => font.replace(/'/g, "\\'")).join(", ")
: fallbackFontFamily.replace(/'/g, "\\'")
};
Array.isArray(fallbackFontFamily)
? fallbackFontFamily.map((font) => font.replace(/'/g, "\\'")).join(", ")
: fallbackFontFamily.replace(/'/g, "\\'")
};
}
`;
return <style dangerouslySetInnerHTML={{ __html: style }} />;
};
};

0 comments on commit d8c80a8

Please sign in to comment.