Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion lib/container.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,9 @@ class Container {
if (!name) {
return container.proxySupport
}
// Always return the proxy to ensure MetaStep creation works
if (typeof container.support[name] === 'function') {
return container.support[name]
}
return container.proxySupport[name]
}

Expand Down Expand Up @@ -600,6 +602,8 @@ function createSupportObjects(config) {
let value
if (container.sharedKeys.has(prop) && prop in container.support) {
value = container.support[prop]
} else if (prop in container.support && typeof container.support[prop] === 'function') {
value = container.support[prop]
} else {
value = lazyLoad(prop)
}
Expand All @@ -614,6 +618,9 @@ function createSupportObjects(config) {
if (container.sharedKeys.has(key) && key in container.support) {
return container.support[key]
}
if (key in container.support && typeof container.support[key] === 'function') {
return container.support[key]
}
return lazyLoad(key)
},
},
Expand Down
2 changes: 1 addition & 1 deletion lib/mocha/inject.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const getInjectedArguments = async (fn, test, suite) => {
testArgs[key] = test.inject[key]
continue
}
if (!objects[key]) {
if (!(key in objects)) {
throw new Error(`Object of type ${key} is not defined in container`)
}
testArgs[key] = container.support(key)
Expand Down
11 changes: 11 additions & 0 deletions test/unit/container_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,17 @@ describe('Container', () => {
expect(container.support('userPage')).is.ok
expect(container.support('userPage').login).is.eql('#login')
})

it('should be able to add and retrieve a function as a support object', async () => {
await container.create({})
const loginFunction = async name => `logged in as ${name}`
container.append({ support: { loginAs: loginFunction } })
expect(container.support('I')).is.ok
const loginAs = container.support('loginAs')
expect(loginAs).to.be.a('function')
const result = await loginAs('admin')
expect(result).to.eql('logged in as admin')
})
})

describe('TypeScript support', () => {
Expand Down
Loading