1313 *
1414 * @param {Object } I - CodeceptJS I object
1515 * @param {Function } conditionFn - Function that returns true when condition is met.
16- * Will be serialized and executed in browser context.
16+ * Will be executed in browser context.
1717 * Should be a pure function with no external dependencies.
1818 * @param {Array } args - Arguments to pass to the condition function
1919 * @param {Object } options - Configuration options
2525const waitForCondition = ( I , conditionFn , args = [ ] , options = { } ) => {
2626 const { timeout = 5000 , pollInterval = 50 , timeoutMessage = "Timeout waiting for condition" } = options ;
2727
28+ // CodeceptJS automatically serializes functions and arguments when passing to executeScript
29+ // This follows the same pattern as existing helpers like waitTicks
2830 return I . executeScript (
29- ( conditionFnStr , args , timeout , pollInterval , timeoutMessage ) => {
31+ ( conditionFn , args , timeout , pollInterval , timeoutMessage ) => {
3032 return new Promise ( ( resolve , reject ) => {
31- // Reconstruct the condition function from string
32- const conditionFn = eval ( `(${ conditionFnStr } )` ) ;
3333 const startTime = Date . now ( ) ;
3434
3535 const checkCondition = ( ) => {
@@ -54,7 +54,7 @@ const waitForCondition = (I, conditionFn, args = [], options = {}) => {
5454 checkCondition ( ) ;
5555 } ) ;
5656 } ,
57- conditionFn . toString ( ) ,
57+ conditionFn ,
5858 args ,
5959 timeout ,
6060 pollInterval ,
0 commit comments