-
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.
test(view): add test for attributes and fragment
- Loading branch information
1 parent
6ad8e31
commit 5b2e920
Showing
3 changed files
with
80 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,46 @@ | ||
import { test } from '@cofn/test-lib/client'; | ||
import { fromView } from './utils.js'; | ||
|
||
const debug = document.getElementById('debug'); | ||
|
||
test('attribute can be interpolated', ({ eq }) => { | ||
const el = fromView( | ||
({ html }) => | ||
({ attributes }) => | ||
html`<p data-id="${attributes['item-id']}">hello</p>`, | ||
); | ||
el.setAttribute('item-id', 'someId'); | ||
debug.appendChild(el); | ||
eq(el.querySelector('p').getAttribute('data-id'), 'someId'); | ||
el.render({ | ||
attributes: { | ||
['item-id']: 'otherId', | ||
}, | ||
}); | ||
eq(el.querySelector('p').getAttribute('data-id'), 'otherId'); | ||
}); | ||
|
||
test('attribute is set when value type is boolean and value is "true", attribute is removed when value is "false"', ({ | ||
eq, | ||
}) => { | ||
const el = fromView( | ||
({ html }) => | ||
({ data } = {}) => | ||
html`<p open="${data?.open}">hello</p>`, | ||
); | ||
debug.appendChild(el); | ||
const pEl = el.querySelector('p'); | ||
el.render({ | ||
data: { | ||
open: true, | ||
}, | ||
}); | ||
eq(pEl.getAttribute('open'), 'true'); | ||
eq(pEl.hasAttribute('open'), true); | ||
el.render({ | ||
data: { | ||
open: false, | ||
}, | ||
}); | ||
eq(pEl.hasAttribute('open'), false); | ||
}); |
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