Skip to content

Commit d373dd9

Browse files
committed
Test: Handle unbound callback this values
1 parent c9d15a4 commit d373dd9

2 files changed

Lines changed: 4 additions & 2 deletions

File tree

‎test/unit/scripts/test/vitest-policy-rules.test.js‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ describe( 'Vitest policy rules', () => {
187187
"import { screen } from '@testing-library/react';\nscreen.getAllByRole( 'button' ).map( condition ? ( button ) => button.offsetWidth : ( item ) => item.value );",
188188
"import { screen } from '@testing-library/react';\nconst callbacks = { width: ( button ) => button.offsetWidth };\nscreen.getAllByRole( 'button' ).map( callbacks.width );",
189189
"import { screen } from '@testing-library/react';\nconst width = ( button ) => button.offsetWidth;\nscreen.getAllByRole( 'button' ).map( width.bind( null ) );",
190+
"import { screen } from '@testing-library/react';\nconst width = ( button ) => button.offsetWidth;\nscreen.getAllByRole( 'button' ).map( width.bind() );",
190191
"import { screen } from '@testing-library/react';\nconst width = ( label, button ) => button.offsetWidth;\nscreen.getAllByRole( 'button' ).map( width.bind( null, 'width' ) );",
191192
"import { screen } from '@testing-library/react';\nconst width = ( label, button ) => button.offsetWidth;\nscreen.getAllByRole( 'button' ).findIndex( width.bind( null, 'width' ) );",
192193
"import { screen } from '@testing-library/react';\nconst width = ( label, button ) => button.offsetWidth;\nscreen.getAllByRole( 'button' ).findLastIndex( width.bind( null, 'width' ) );",

‎test/unit/scripts/vitest-policy-rules.mjs‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1249,6 +1249,7 @@ function getReachableLocalValues(
12491249
node.callee?.type === 'MemberExpression' &&
12501250
getMemberPropertyName( node.callee ) === 'bind'
12511251
) {
1252+
const boundArgumentCount = Math.max( 0, node.arguments.length - 1 );
12521253
for ( const value of getReachableLocalValues(
12531254
node.callee.object,
12541255
useNode,
@@ -1260,7 +1261,7 @@ function getReachableLocalValues(
12601261
localValues.add( {
12611262
...value,
12621263
boundArgumentCount:
1263-
value.boundArgumentCount + node.arguments.length - 1,
1264+
value.boundArgumentCount + boundArgumentCount,
12641265
} );
12651266
} else if (
12661267
[
@@ -1272,7 +1273,7 @@ function getReachableLocalValues(
12721273
localValues.add( {
12731274
type: 'BoundFunction',
12741275
functionNode: value,
1275-
boundArgumentCount: node.arguments.length - 1,
1276+
boundArgumentCount,
12761277
} );
12771278
}
12781279
}

0 commit comments

Comments
 (0)