mirror of
https://github.com/pyscript/pyscript.git
synced 2025-12-19 18:27:29 -05:00
Add more type definitions (#882)
* More typing to base.ts * Add more types * More types
This commit is contained in:
34
pyscriptjs/tests/unit/utils.test.ts
Normal file
34
pyscriptjs/tests/unit/utils.test.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
import { jest } from "@jest/globals"
|
||||
import { ensureUniqueId } from "../../src/utils"
|
||||
|
||||
describe("Utils", () => {
|
||||
|
||||
let element: HTMLElement;
|
||||
|
||||
beforeEach(() => {
|
||||
element = document.createElement("div");
|
||||
})
|
||||
|
||||
it("ensureUniqueId sets unique id on element", async () => {
|
||||
expect(element.id).toBe("")
|
||||
|
||||
ensureUniqueId(element)
|
||||
|
||||
expect(element.id).toBe("py-internal-0")
|
||||
})
|
||||
|
||||
it("ensureUniqueId sets unique id with increasing counter", async () => {
|
||||
const secondElement = document.createElement("div")
|
||||
|
||||
expect(element.id).toBe("")
|
||||
expect(secondElement.id).toBe("")
|
||||
|
||||
ensureUniqueId(element)
|
||||
ensureUniqueId(secondElement)
|
||||
|
||||
// The counter will have been incremented on
|
||||
// the previous test, make sure it keeps increasing
|
||||
expect(element.id).toBe("py-internal-1")
|
||||
expect(secondElement.id).toBe("py-internal-2")
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user