-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
sp-element-title: add unit tests / observe text attribute / tidy stor…
…ybook
- Loading branch information
1 parent
70953c2
commit a1c609c
Showing
4 changed files
with
56 additions
and
19 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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,37 @@ | ||
import { describe, expect, test } from "vitest"; | ||
import { getByShadowRole } from "shadow-dom-testing-library"; | ||
import { SpElementTitle } from "../../src/components/elementTitle/sp-element-title"; | ||
import "../../src/components/elementTitle/sp-element-title"; | ||
|
||
function getSpElementTitle() { | ||
return document.querySelector("sp-element-title") as SpElementTitle; | ||
} | ||
|
||
function getHeadingElement() { | ||
return getByShadowRole(document.body, "heading"); | ||
} | ||
|
||
describe("sp-element-title", () => { | ||
describe("text属性", () => { | ||
test("text属性を設定すると、そのテキストが見出しとして表示される", async () => { | ||
document.body.innerHTML = | ||
"<sp-element-title text='サンプルタイトル'></sp-element-title>"; | ||
|
||
const headingElement = getHeadingElement(); | ||
|
||
expect(headingElement.textContent).toBe("サンプルタイトル"); | ||
}); | ||
|
||
test("text属性を更新すると、更新後のテキストが表示される", async () => { | ||
document.body.innerHTML = | ||
"<sp-element-title text='初期タイトル'></sp-element-title>"; | ||
|
||
const spElementTitle = getSpElementTitle(); | ||
const headingElement = getHeadingElement(); | ||
|
||
spElementTitle.setAttribute("text", "更新後タイトル"); | ||
|
||
expect(headingElement.textContent).toBe("更新後タイトル"); | ||
}); | ||
}); | ||
}); |