-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Add test utils to astro core #4200
Conversation
|
@@ -0,0 +1,2 @@ | |||
/// <reference path="./astro-jsx.d.ts" /> | |||
export function render(vnode: astroHTML.JSX.Element): Promise<{ container: HTMLTemplateElement }>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be cool if this function also worked inside of .astro components, can we make this accept a non-JSX astro type? I'm thinking I'd love to be able to do:
src/components/Greeting.test.astro
---
import { expect, test } from 'vitest'
import { render } from 'astro/test'
import Greeting from './Greeting.astro'
test('Greeting', async () => {
const { container } = await render(Greeting, { props: 'here' })
expect(container).toBeDefined()
expect(container.textContent).toBe('Hello world')
})
---
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I realize that the above probably doesn't work for some reasons, just noting that it would be nice if this generically named render
function can be extended in the future for non-JSX test files.
import { render } from 'astro/test' | ||
import Greeting from './Greeting.astro' | ||
|
||
test('Greeting', async () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
:partyblob:
This is stale so closing, please reopen if you're about to update it. |
Hey @natemoo-re 👋 I've been digging into possible unit testing strategies for Astro... Just wondering what happened with this PR, it looked promising! |
Hey, thanks for asking! This is something we're interested in circling back to. We were originally blocked by the lack of a user-facing API for rendering Astro components to a string. Internally, it required the full The proposal actually came out of this exploration specifically. Hoping to implement in early 2024! |
Thanks for the quick reply man! Just to be clear, did the original proposal in this PR actually work? I assume the issue around the Really hopeful to see progress on 533 and would love to contribute if I can, hence all this poking around (at 11.30pm on Christmas Eve 🎄 ) |
Changes
astro/test
with some helpful utilities for testing Astro componentsTesting
TODO
Docs
TODO