-
Notifications
You must be signed in to change notification settings - Fork 879
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[lit-labs/ssr-dom-shim] shim Element.prototype.toggleAttribute method (…
- Loading branch information
1 parent
851334c
commit e901c58
Showing
8 changed files
with
73 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@lit-labs/ssr-dom-shim': minor | ||
--- | ||
|
||
Add `toggleAttribute` to the Element shim. |
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
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 |
---|---|---|
@@ -1,2 +1,3 @@ | ||
/index.* | ||
/lib/ | ||
/test/ |
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,41 @@ | ||
/** | ||
* @license | ||
* Copyright 2024 Google LLC | ||
* SPDX-License-Identifier: BSD-3-Clause | ||
*/ | ||
|
||
import {suite} from 'uvu'; | ||
// eslint-disable-next-line import/extensions | ||
import * as assert from 'uvu/assert'; | ||
import {HTMLElement} from '@lit-labs/ssr-dom-shim'; | ||
|
||
const test = suite('Element Shim'); | ||
|
||
test('toggleAttribute adds and removes attributes', () => { | ||
const shimmedEl = new HTMLElement(); | ||
assert.ok(shimmedEl.toggleAttribute('potato')); | ||
assert.ok(shimmedEl.hasAttribute('potato')); | ||
assert.not.ok(shimmedEl.toggleAttribute('potato')); | ||
assert.not.ok(shimmedEl.hasAttribute('potato')); | ||
}); | ||
|
||
test('toggleAttribute accepts an optional force parameter', () => { | ||
const shimmedEl = new HTMLElement(); | ||
assert.not.ok(shimmedEl.toggleAttribute('potato', false)); | ||
assert.not.ok(shimmedEl.hasAttribute('potato')); | ||
assert.ok(shimmedEl.toggleAttribute('potato', true)); | ||
assert.ok(shimmedEl.hasAttribute('potato')); | ||
// A no-op, ensuring attribute remains | ||
assert.ok(shimmedEl.toggleAttribute('potato', true)); | ||
assert.ok(shimmedEl.hasAttribute('potato')); | ||
}); | ||
|
||
test('setAttribute silently casts values to a string', () => { | ||
const shimmedEl = new HTMLElement(); | ||
// It is possible to pass any value to `setAttribute`, and we | ||
// silently convert it to a string. | ||
shimmedEl.setAttribute('tomato', {} as unknown as string); | ||
assert.equal(shimmedEl.getAttribute('tomato'), '[object Object]'); | ||
}); | ||
|
||
test.run(); |