Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(Static Template): Ensure valid HTML formatting for static template (
#894) Co-authored-by: Danilo Woznica <danilowoz@gmail.com>
- Loading branch information
1 parent
fd40625
commit af68579
Showing
4 changed files
with
89 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/** | ||
* @jest-environment jsdom | ||
*/ | ||
|
||
import { validateHtml } from "./utils"; | ||
|
||
describe(validateHtml, () => { | ||
it("returns a valid HTML string", () => { | ||
const content = | ||
"<html><head><title>Test</title></head><body><p>Hello world!</p></body></html>"; | ||
const validatedContent = validateHtml(content); | ||
|
||
expect(validatedContent).toContain("<!DOCTYPE html>"); | ||
expect(validatedContent).toContain( | ||
'<html lang="en"><head><title>Test</title></head><body><p>Hello world!</p></body></html>' | ||
); | ||
}); | ||
|
||
it("adds html/head/body tags to an empty string", () => { | ||
const content = ""; | ||
const validatedContent = validateHtml(content); | ||
|
||
expect(validatedContent).toContain("<!DOCTYPE html>"); | ||
expect(validatedContent).toContain( | ||
'<html lang="en"><head></head><body></body></html>' | ||
); | ||
}); | ||
|
||
it("shouldn't change anything if a valid document is provided ", () => { | ||
const content = `<!DOCTYPE html> | ||
<html lang="en"><head></head> | ||
<body> | ||
<h1>Hello World</h1> | ||
</body></html>`; | ||
|
||
expect(validateHtml(content)).toBe(content); | ||
}); | ||
|
||
it("should add the lang attribute to the html if not provided", () => { | ||
const content = `<!DOCTYPE html> | ||
<html> | ||
<head></head> | ||
<body> | ||
<h1>Hello World</h1> | ||
</body> | ||
</html>`; | ||
|
||
const validatedContent = validateHtml(content); | ||
|
||
expect(validatedContent).toContain("<!DOCTYPE html>"); | ||
expect(validatedContent).toContain('<html lang="en">'); | ||
}); | ||
|
||
it("shouldn't change the land attr if a custom value is provided", () => { | ||
const content = `<!DOCTYPE html> | ||
<html lang="pt-BR"> | ||
<head></head> | ||
<body> | ||
<h1>Hello World</h1> | ||
</body> | ||
</html>`; | ||
|
||
const validatedContent = validateHtml(content); | ||
|
||
expect(validatedContent).toContain("<!DOCTYPE html>"); | ||
expect(validatedContent).toContain('<html lang="pt-BR">'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
af68579
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
sandpack-docs – ./website/docs
sandpack-docs-codesandbox1.vercel.app
sandpack-docs-git-main-codesandbox1.vercel.app
sandpack-docs.codesandbox.io
sandpack.vercel.app