Skip to content

Commit

Permalink
Fix async functions (#114)
Browse files Browse the repository at this point in the history
* add a failing test

* fix #113 - async functions
  • Loading branch information
nichoth authored Oct 11, 2023
1 parent 49fecbf commit 811461f
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
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

0 comments on commit 811461f

Please sign in to comment.