Repository navigation
4.x: DataTable fails: Error: Invalid data type. Data accepts either: DataTable || generator || Array || function #5641
Copy link
Copy link
Closed
Description
Activity
AI suggests this fix:
diff --git a/lib/data/context.js b/lib/data/context.js index c2e0bc2..b0744d2 100644 --- a/lib/data/context.js +++ b/lib/data/context.js @@ -83,7 +83,7 @@ function isTableDataRow(row) { } function detectDataType(dataTable) { - if (dataTable instanceof DataTable) { + if (dataTable instanceof DataTable || (dataTable && Array.isArray(dataTable.rows) && typeof dataTable.add === 'function')) { return dataTable.rows }
The bug was fixed by #5640 (4.1.0 beta 1), but there is one more issue
SyntaxError: Unexpected token (1:3)then. I hit the issue also in 4.0 when I solved #5641 by a patch.test:
const userRoles = new DataTable(["role", "sideBarMenu"]); userRoles.add([Role.BLOCK_ADMIN, "blockAdmin"]); userRoles.add([Role.SUPER_MENTOR, "superMentor"]); userRoles.add([Role.MENTOR, "mentor"]); userRoles.add([Role.USER, "teacher"]); userRoles.add([Role.SCHOOL_ADMIN, "schoolAdmin"]); Data(userRoles).Scenario("Set roles to the user", ({ current }) => { let entity_type: EntityType; let entity_id: string; switch (current.role) { default: case Role.USER: entity_type = EntityType.TENANT; entity_id = String(tenantId); break; case Role.BLOCK_ADMIN: entity_type = EntityType.BLOCK; entity_id = String(blockId); break; case Role.SUPER_MENTOR: case Role.MENTOR: entity_type = EntityType.COURSE; entity_id = String(course.id); break; case Role.SCHOOL_ADMIN: entity_type = EntityType.SCHOOL; entity_id = String(school.id); break; } I.setUserRole( { role: current.role, entity_type, entity_id, user_id: userId, }, adminToken, ); });
output:
Course Mentoring disabled: Verify Dashboard tabs | {"role":"ROLE_BLOCK_ADMIN","sideBarMenu":"blockAdmin"} › Test Timeout: 600s › [Dir] /home/mirao/workspace/codeceptjs/tests/s4w Scenario() Error in ({current})=>{if([Role.USER,Role.SCHOOL_ADMIN].includes(current.role)){I.click(sideBarMenu.dashboard[current.sideBarMenu].loc);for(const[index,text]of dashboardTabsPage[current.role].entries()){if(current.role===Role.SCHOOL_ADMIN&&(index===2||index===3)){I.dontSeeElement(dashboardTabsPage.tab.at(index+1))}else{I.seeTextEquals(text,dashboardTabsPage.tab.at(index+1))}}}else{I.dontSeeElement(sideBarMenu.dashboard[current.sideBarMenu].loc)}} SyntaxError: Unexpected token (1:3) [6] Error | TypeError: Cannot read properties of undefined (reading 'role') undefined... [6] <teardown> Stopping recording promises › <screenshot> Saving screenshot Course_Mentoring_disabled__Verify_Dashboard_tabs.failed.png › [Screenshot] output/Course_Mentoring_disabled__Verify_Dashboard_tabs.failed.png ✖ FAILED in 26ms- added a commit that references this issue
on Jun 19, 2026
Metadata
Metadata
Assignees
Labels
No labels
Found in my production project after the migration from 3.x to 4.x. It works well in 3.x
Maybe the bug has the same reason as #5632 and #5635.
You can reproduce it with the Quickstart project
tests/My_test.ts:
codecept.conf.ts:
tsconfig.json:
{ "compilerOptions": { "target": "ES2022", "lib": ["ES2022", "DOM"], "esModuleInterop": true, "module": "ESNext", "moduleResolution": "bundler", "strictNullChecks": false, "types": ["codeceptjs", "node"], "declaration": true, "skipLibCheck": true }, "exclude": ["node_modules"] }Used SW: