Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix async functions #114

Merged
merged 2 commits into from
Oct 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ export class Tonic extends window.HTMLElement {
}
case '[object Object]':
case '[object Function]':
case '[object AsyncFunction]':
case '[object Set]':
case '[object Map]':
case '[object WeakMap]': return this._prop(o)
Expand Down
39 changes: 39 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,45 @@ test('sanity', async t => {
t.ok(parseInt(parts[0]) >= 10)
})

test('pass an async function as an event handler', t => {
t.plan(1)

class TheApp extends Tonic {
async clicker (msg) {
t.equal(msg, 'hello', 'should get the event')
}

render () {
return this.html`<div>
<fn-example onbtnclick=${this.clicker.bind(this)}></fn-example>
</div>`
}
}

class FnExample extends Tonic {
click (ev) {
ev.preventDefault()
this.props.onbtnclick('hello')
}

render () {
return this.html`<div id="fn-test">
example
<button id="btn">clicker</button>
</div>`
}
}

document.body.innerHTML = `
<the-app></the-app>
`

Tonic.add(FnExample)
Tonic.add(TheApp)

document.getElementById('btn').click()
})

test('get kebab case from camel case', t => {
const kebab = Tonic.getTagName('MyExample')
t.equal(typeof kebab, 'string', 'should return a string')
Expand Down