Add test for suffix hydration (#4982)

This commit is contained in:
Bjorn Lu 2022-10-06 22:36:50 +08:00 committed by GitHub
parent 50a397c4ba
commit 9683ae64ff
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 25 additions and 0 deletions

View file

@ -0,0 +1,10 @@
import React, { useState } from 'react';
export default function () {
const [open, setOpen] = useState(false);
return (
<button id="suffix" onClick={() => setOpen(!open)}>
suffix toggle {open.toString()}
</button>
);
}

View file

@ -1,6 +1,7 @@
---
import Counter from '../components/Counter.jsx';
import ReactComponent from '../components/JSXComponent.jsx';
import Suffix from '../components/Suffix.react';
const someProps = {
count: 0,
@ -33,5 +34,7 @@ const someProps = {
</Counter>
<ReactComponent id="client-only" client:only="react" />
<Suffix client:load />
</body>
</html>

View file

@ -1,3 +1,4 @@
import { expect } from '@playwright/test';
import { prepareTestFactory } from './shared-component-tests.js';
const { test, createTests } = prepareTestFactory({ root: './fixtures/react-component/' });
@ -30,3 +31,14 @@ test.describe('React components in MDX files', () => {
pageSourceFilePath: './src/pages/mdx.mdx',
});
});
test.describe('dev', () => {
test('Loads .react suffix', async ({ page, astro }) => {
await page.goto(astro.resolveUrl('/'));
const suffix = page.locator('#suffix');
expect(await suffix.textContent()).toBe('suffix toggle false');
await suffix.click();
expect(await suffix.textContent()).toBe('suffix toggle true');
});
});