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

Added tests for mithril #11

Merged
merged 1 commit into from
Sep 17, 2018
Merged

Conversation

karthikiyengar
Copy link
Contributor

I've used a wait in the tests because mithril renders on nextTick. I'm unsure if this is the right way to test it though.

const {getByText} = getQueriesForElement(div)
const counter = getByText('0')
fireEvent.click(counter)
await wait(() => expect(counter).toHaveTextContent('1'))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of using wait here, could you use fireEventAsync (see hyperapp.test.js for an example).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's what I tried to begin with, but the test suite still fails. Here's the code:

test('renders a counter', async () => {
  const div = document.createElement('div')
  m.mount(div, Counter)

  const {getByText} = getQueriesForElement(div)
  const counter = getByText('0')
  await fireEventAsync.click(counter)
  expect(counter).toHaveTextContent('1')

  await fireEventAsync.click(counter)
  expect(counter).toHaveTextContent('2')
})

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Weird. Maybe it takes longer than a single tick of the event loop to rerender for some reason. Ok, thanks!

@kentcdodds kentcdodds merged commit abfafba into kentcdodds:master Sep 17, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants