diff --git a/lib/container.js b/lib/container.js index 6bf89ba92..cae94a772 100644 --- a/lib/container.js +++ b/lib/container.js @@ -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] } @@ -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) } @@ -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) }, }, diff --git a/test/unit/container_test.js b/test/unit/container_test.js index 1a3dd0a89..0a7f4dbee 100644 --- a/test/unit/container_test.js +++ b/test/unit/container_test.js @@ -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', () => {