Skip to content

Commit 9b531cd

Browse files
committed
fix: get helpers dynamically in config listener to avoid undefined errors
The config listener was capturing a static snapshot of helpers at initialization time, which could contain empty placeholder objects during async helper loading. This caused 'Cannot read properties of undefined (reading name)' errors when tests tried to access helper properties. Changes: - Move helpers retrieval inside event handler to get runtime instances - Add guard clause to check helper validity before accessing properties - Ensures we always get fully initialized helper instances, not placeholders Fixes issue where actor I was empty {} and helper.constructor.name threw undefined errors during Scenario execution.
1 parent 5ad33dc commit 9b531cd

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

lib/listener/config.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,23 @@ export default function () {
1212
return
1313
}
1414
global.__codeceptConfigListenerInitialized = true
15-
16-
const helpers = global.container.helpers()
1715

1816
enableDynamicConfigFor('suite')
1917
enableDynamicConfigFor('test')
2018

2119
function enableDynamicConfigFor(type) {
2220
event.dispatcher.on(event[type].before, (context = {}) => {
21+
// Get helpers dynamically at runtime, not at initialization time
22+
// This ensures we get the actual helper instances, not placeholders
23+
const helpers = global.container.helpers()
24+
2325
function updateHelperConfig(helper, config) {
26+
// Guard against undefined or invalid helpers
27+
if (!helper || !helper.constructor) {
28+
output.debug(`[${ucfirst(type)} Config] Helper not found or not properly initialized`)
29+
return
30+
}
31+
2432
const oldConfig = deepClone(helper.options)
2533
try {
2634
helper._setConfig(deepMerge(deepClone(oldConfig), config))
@@ -41,7 +49,7 @@ export default function () {
4149
for (let name in context.config) {
4250
const config = context.config[name]
4351
if (name === '0') {
44-
// first helper
52+
// first helper - get dynamically
4553
name = Object.keys(helpers)[0]
4654
}
4755
const helper = helpers[name]

0 commit comments

Comments
 (0)