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

Add test for suffix hydration #4982

Merged
merged 2 commits into from
Oct 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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>
);
}
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -33,5 +34,7 @@ const someProps = {
</Counter>

<ReactComponent id="client-only" client:only="react" />

<Suffix client:load />
</body>
</html>
12 changes: 12 additions & 0 deletions packages/astro/e2e/react-component.test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { expect } from '@playwright/test';
import { prepareTestFactory } from './shared-component-tests.js';

const { test, createTests } = prepareTestFactory({ root: './fixtures/react-component/' });
Expand Down Expand Up @@ -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');
});
});