Skip to content

Commit

Permalink
test: test
Browse files Browse the repository at this point in the history
  • Loading branch information
nolanlawson committed Sep 20, 2024
1 parent 856a68a commit da6f4ed
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 16 deletions.
4 changes: 4 additions & 0 deletions src/picker/components/Picker/framework.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ function patch (expressions, instanceBindings) {

const expression = expressions[expressionIndex]

if (import.meta.env.MODE !== 'production' && expression === undefined && (attributeValuePre || attributeValuePost)) {
throw new Error('framework does not support undefined expressions with attribute pre/post')
}

if (currentExpression === expression) {
// no need to update, same as before
continue
Expand Down
24 changes: 8 additions & 16 deletions test/spec/picker/framework.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,26 +118,18 @@ describe('framework', () => {
expect(node.getAttribute('aria-selected')).toBe(null)
})

test('set to undefined then something then back to undefined - with pre/post text', () => {
test('set to undefined - with pre/post text', () => {
const state = { value: undefined }
const { html } = createFramework(state)

let node
const render = () => {
node = html`<div class="foo ${state.value} bar"></div>`
const renders = [
() => html`<div class="foo ${state.value}"></div>`,
() => html`<div class="${state.value} bar"></div>`,
() => html`<div class="foo ${state.value} bar"></div>`
]
for (const render of renders) {
expect(render).toThrow(/framework does not support undefined expressions with attribute pre\/post/)
}

render()
// expect(node.getAttribute('class')).toBe('foo undefined bar')
expect(node.getAttribute('class')).toBe(null) // we don't handle the initial undefined case correctly

state.value = true
render()
expect(node.getAttribute('class')).toBe('foo true bar')

state.value = undefined
render()
expect(node.getAttribute('class')).toBe('foo undefined bar')
})

// Framework no longer supports this since we switched from HTML comments to text nodes
Expand Down

0 comments on commit da6f4ed

Please sign in to comment.