Skip to content

Commit

Permalink
Ensure attributes have been updated before checking the values (#61615)
Browse files Browse the repository at this point in the history
Co-authored-by: DAreRodz <darerodz@git.wordpress.org>
Co-authored-by: Mamaduka <mamaduka@git.wordpress.org>
Co-authored-by: sirreal <jonsurrell@git.wordpress.org>
  • Loading branch information
4 people authored May 13, 2024
1 parent 2a14725 commit aa74ab0
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
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

0 comments on commit aa74ab0

Please sign in to comment.