Skip to content

Commit 784904c

Browse files
author
DavertMik
committed
fixed printing metasteps
1 parent 1f54ace commit 784904c

File tree

3 files changed

+34
-16
lines changed

3 files changed

+34
-16
lines changed

lib/container.js

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,16 @@ function createSupportObjects(config) {
274274
{},
275275
{
276276
get(target, prop) {
277+
// behavr like array or
278+
if (prop === 'length') return Object.keys(config).length
279+
if (prop === Symbol.iterator) {
280+
return function* () {
281+
for (let i = 0; i < Object.keys(config).length; i++) {
282+
yield target[i]
283+
}
284+
}
285+
}
286+
277287
// load actual name from vocabulary
278288
if (container.translation.name) {
279289
name = container.translation.name
@@ -304,10 +314,10 @@ function createSupportObjects(config) {
304314
let currentValue = currentObject[prop]
305315

306316
if (isFunction(currentValue) || isAsyncFunction(currentValue)) {
307-
const ms = new MetaStep(name, currentValue)
317+
const ms = new MetaStep(name, prop)
308318
ms.setContext(currentObject)
309319
if (isAsyncFunction(currentValue)) currentValue = asyncWrapper(currentValue)
310-
currentObject[prop] = ms.run.bind(ms, currentValue)
320+
return ms.run.bind(ms, currentValue)
311321
}
312322

313323
return currentValue
@@ -317,8 +327,14 @@ function createSupportObjects(config) {
317327
return prop in container.support[name]
318328
},
319329
ownKeys() {
330+
const keys = []
331+
// Add numeric indices
332+
for (let i = 0; i < Object.keys(config).length; i++) {
333+
keys.push(String(i))
334+
}
335+
// Add other properties
320336
container.support[name] = container.support[name] || loadSupportObject(config[name])
321-
return Reflect.ownKeys(container.support[name])
337+
return [...keys, ...Reflect.ownKeys(container.support[name])]
322338
},
323339
},
324340
)
@@ -350,8 +366,6 @@ function createActor(actorPath) {
350366
container.support.I = actor()
351367
}
352368

353-
container.support.I = container.support.I
354-
355369
return container.support.I
356370
}
357371

@@ -420,12 +434,16 @@ function loadSupportObject(modulePath, supportObjectName) {
420434
if (typeof obj === 'function') {
421435
// If it's a class (constructor function)
422436
if (obj.prototype && obj.prototype.constructor === obj) {
423-
const ClassName = obj;
424-
return new ClassName();
437+
const ClassName = obj
438+
return new ClassName()
425439
}
426440
// If it's a regular function
427441
return obj()
428442
}
443+
if (obj && Array.isArray(obj)) {
444+
return obj
445+
}
446+
429447
// If it's a plain object
430448
if (obj && typeof obj === 'object' && !Array.isArray(obj)) {
431449
return obj
Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
const { notpage, arraypage } = inject();
1+
const { notpage, arraypage } = inject()
22

33
module.exports = {
44
type: (s) => {
5-
console.log('type => ', s);
6-
console.log('strategy', arraypage);
7-
notpage.domainIds.push('newdomain');
8-
return notpage.domainIds;
5+
console.log('type => ', s)
6+
console.log('strategy', arraypage.toString())
7+
notpage.domainIds.push('newdomain')
8+
return notpage.domainIds
99
},
1010

1111
purgeDomains: (s) => {
12-
console.log('purgeDomains');
13-
console.log(s);
12+
console.log('purgeDomains')
13+
console.log(s)
1414
},
15-
};
15+
}

test/runner/pageobject_test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ describe('CodeceptJS PageObject', () => {
157157
it('should inject page objects via proxy', (done) => {
158158
exec(`${config_run_config('../../../inject-fail-example')} --debug`, (err, stdout) => {
159159
expect(stdout).toContain('newdomain')
160-
expect(stdout).toContain("[ 'veni', 'vedi', 'vici' ]", 'array objects work')
160+
expect(stdout).toContain('veni,vedi,vici')
161161
expect(stdout).toContain('OK | 1 passed')
162162
expect(err).toBeFalsy()
163163
done()

0 commit comments

Comments
 (0)