-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(atomic): fix display-if directive for lit components (#4988)
- Loading branch information
1 parent
a8ed5e9
commit d6ef356
Showing
2 changed files
with
55 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import {html, LitElement} from 'lit'; | ||
import {customElement, property} from 'lit/decorators.js'; | ||
import {describe, beforeEach, test, expect} from 'vitest'; | ||
import {displayIf} from './display-if'; | ||
|
||
describe('displayIf', () => { | ||
let element: TestElement; | ||
|
||
@customElement('test-element') | ||
class TestElement extends LitElement { | ||
@property({type: Boolean, reflect: true}) shouldDisplay = true; | ||
|
||
render() { | ||
return html`${displayIf( | ||
this.shouldDisplay, | ||
html`<span id="content">Visible</span>` | ||
)}`; | ||
} | ||
} | ||
|
||
beforeEach(() => { | ||
element = document.createElement('test-element') as TestElement; | ||
document.body.appendChild(element); | ||
}); | ||
|
||
afterEach(() => { | ||
document.body.removeChild(element); | ||
}); | ||
|
||
test('should not add "atomic-hidden" when the condition is "true"', async () => { | ||
element.shouldDisplay = true; | ||
await element.updateComplete; | ||
expect(element.classList.contains('atomic-hidden')).toBe(false); | ||
}); | ||
|
||
test('should add "atomic-hidden" when the condition is "false"', async () => { | ||
element.shouldDisplay = false; | ||
await element.updateComplete; | ||
expect(element.classList.contains('atomic-hidden')).toBe(true); | ||
}); | ||
|
||
test('should render the children when the condition is "true"', async () => { | ||
element.shouldDisplay = true; | ||
await element.updateComplete; | ||
expect(element.shadowRoot?.querySelector('#content')).not.toBeNull(); | ||
}); | ||
|
||
test('should not render the children when the condition is "false"', async () => { | ||
element.shouldDisplay = false; | ||
await element.updateComplete; | ||
expect(element.shadowRoot?.querySelector('#content')).toBeNull(); | ||
}); | ||
}); |
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