developit / htm

Hyperscript Tagged Markup: JSX alternative using standard tagged templates, with compiler support.
Apache License 2.0
8.73k stars 170 forks source link

Testing example needed #228

Closed RapidOwl closed 2 years ago

RapidOwl commented 2 years ago

I'm really sorry to create another issue about this (previous issue). I thought I'd got it solved after the switch to Vitest, but I just can't figure it out.

I'm trying to test a single functional component, but for some reason other functions in the component's file are being executed (and erroring) and I don't understand why.

Here's the test file: https://github.com/RapidOwl/qaas/blob/testing/src/quiz.test.js

Errors:

The errors are occurring in the RenderQuiz function, which I'm not even executing as part of this test.

Please can someone link me to an example of Preact + HTM testing that I can crib from. I don't want to switch to JSX + Enzyme as I really like the minimal development experience.

rschristian commented 2 years ago

Hello,

The errors are occurring in the RenderQuiz function, which I'm not even executing as part of this test.

Actually, you are. You've mixed up default & named exports in your test I'm afraid.

import Result from './quiz';  --> RenderQuiz()

import { Result } from './quiz'; --> Result()

Happens to all of us.

RapidOwl commented 2 years ago

Oh good grief! I’m such a newb!

Thank you so much for taking the time to help.

rschristian commented 2 years ago

No worries.

That should fix your issues and get you a working test.

RapidOwl commented 2 years ago

That worked. Now I just need to sort out import aliases for Vitest so I can keep using CDN imports in the browser.

Thanks again!