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

Interactivity API: Fix flaky tests for attribute hydration #61615

Merged
merged 1 commit into from
May 13, 2024
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
Expand Up @@ -93,6 +93,7 @@
<button
data-testid="toggle value"
data-wp-on--click="actions.toggleValue"
data-wp-bind--data-toggle-count="context.count"
>Toggle</button>
</div>
<?php endforeach; ?>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const { state, foo } = store( 'directive-bind', {

context.previousValue = context.value;
context.value = previousValue;
context.count = ( context.count ?? 0 ) + 1;
},
},
} );
14 changes: 13 additions & 1 deletion test/e2e/specs/interactivity/directive-bind.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,12 @@ test.describe( 'data-wp-bind', () => {
const el = container.getByTestId( testid );
const toggle = container.getByTestId( 'toggle value' );

// Ensure hydration has happened.
const checkbox = page.getByTestId(
'add missing checked at hydration'
);
await expect( checkbox ).toBeChecked();

const hydratedAttr = await el.getAttribute( name );
const hydratedProp = await el.evaluate(
( node, propName ) => ( node as any )[ propName ],
Expand All @@ -236,7 +242,13 @@ test.describe( 'data-wp-bind', () => {
return;
}

await toggle.click( { clickCount: 2, delay: 50 } );
await toggle.click( { clickCount: 2 } );

// Ensure values have been updated after toggling.
await expect( toggle ).toHaveAttribute(
'data-toggle-count',
'2'
);

// Values should be the same as before.
const renderedAttr = await el.getAttribute( name );
Expand Down
Loading