diff --git a/config/matchers.js b/config/matchers.js index a8e297a..4afd258 100644 --- a/config/matchers.js +++ b/config/matchers.js @@ -50,6 +50,22 @@ const getMatchers = () => ({ }; return { actual: received, pass, message }; + }, + toBeIterable(received, ignoreStrings = false) { + const exists = received != null; + const isIterable = + exists && typeof received[Symbol.iterator] === 'function'; + const isMatch = !ignoreStrings + ? isIterable + : typeof received === 'string' ? false : isIterable; + const message = () => + this.utils.matcherHint(`${isMatch ? '.not' : ''}.toBeIterable`) + + '\n\n' + + `Expected value ${isMatch ? 'not ' : ''}to be Iterable${ + ignoreStrings ? ' (ignoring strings)' : '' + }, instead received:\n` + + ` ${this.utils.printReceived(received)}`; + return { actual: received, pass: isMatch, message }; } }); diff --git a/packages/tao/src/AppCtxHandlers.js b/packages/tao/src/AppCtxHandlers.js index 77736cc..a4f84d9 100644 --- a/packages/tao/src/AppCtxHandlers.js +++ b/packages/tao/src/AppCtxHandlers.js @@ -2,6 +2,11 @@ import AppCtxRoot from './AppCtxRoot'; import AppCtx from './AppCtx'; import { isIterable } from './utils'; +const console = { + error: () => 1, + log: () => 1 +}; + export default class AppCtxHandlers extends AppCtxRoot { constructor(term, action, orient, leafAppConHandlers) { super(term, action, orient); @@ -98,15 +103,15 @@ export default class AppCtxHandlers extends AppCtxRoot { // populateHandlersFromWildcards() {} get interceptHandlers() { - return this._intercept; + return this._intercept.values(); } get asyncHandlers() { - return this._async; + return this._async.values(); } get inlineHandlers() { - return this._inline; + return this._inline.values(); } async handleAppCon(ac, setAppCtx) { diff --git a/packages/tao/src/AppCtxHandlers.spec.js b/packages/tao/src/AppCtxHandlers.spec.js index f9ff5d0..c97eb74 100644 --- a/packages/tao/src/AppCtxHandlers.spec.js +++ b/packages/tao/src/AppCtxHandlers.spec.js @@ -45,6 +45,18 @@ describe('AppCtxHandlers exports a class extending AppCtxRoot', () => { describe('AppCtxHandlers is used to attach handlers for Application Contexts', () => { describe('as Inline handlers', () => { + it('should expose an inlineHandlers iterable property that is not the underlying collection', () => { + // Assemble + const uut = new AppCtxHandlers(TERM, ACTION, ORIENT); + // Act + // Assert + expect(uut.inlineHandlers).toBeDefined(); + expect(uut.inlineHandlers).toBeIterable(true); + expect(uut.inlineHandlers).not.toBeInstanceOf(Set); + expect(uut.inlineHandlers).not.toBeInstanceOf(Array); + expect(uut.inlineHandlers).not.toBeInstanceOf(Map); + }); + it('should throw if handler is not a function', () => { // Assemble const uut = new AppCtxHandlers(); @@ -58,6 +70,7 @@ describe('AppCtxHandlers is used to attach handlers for Application Contexts', ( // Assemble const uut = new AppCtxHandlers(TERM, ACTION, ORIENT); const handler = jest.fn(); + // const beforeAttach = Array.from() // Act uut.addInlineHandler(handler); // Assert @@ -240,6 +253,18 @@ describe('AppCtxHandlers is used to attach handlers for Application Contexts', ( }); describe('as Async handlers', () => { + it('should expose an asyncHandlers iterable property that is not the underlying collection', () => { + // Assemble + const uut = new AppCtxHandlers(TERM, ACTION, ORIENT); + // Act + // Assert + expect(uut.asyncHandlers).toBeDefined(); + expect(uut.asyncHandlers).toBeIterable(true); + expect(uut.asyncHandlers).not.toBeInstanceOf(Set); + expect(uut.asyncHandlers).not.toBeInstanceOf(Array); + expect(uut.asyncHandlers).not.toBeInstanceOf(Map); + }); + it('should throw if handler is not a function', () => { // Assemble const uut = new AppCtxHandlers(); @@ -464,6 +489,18 @@ describe('AppCtxHandlers is used to attach handlers for Application Contexts', ( }); describe('as Intercept handlers', () => { + it('should expose an interceptHandlers iterable property that is not the underlying collection', () => { + // Assemble + const uut = new AppCtxHandlers(TERM, ACTION, ORIENT); + // Act + // Assert + expect(uut.interceptHandlers).toBeDefined(); + expect(uut.interceptHandlers).toBeIterable(true); + expect(uut.interceptHandlers).not.toBeInstanceOf(Set); + expect(uut.interceptHandlers).not.toBeInstanceOf(Array); + expect(uut.interceptHandlers).not.toBeInstanceOf(Map); + }); + it('should throw if handler is not a function', () => { // Assemble const uut = new AppCtxHandlers(); diff --git a/packages/tao/src/Kernel.spec.js b/packages/tao/src/Kernel.spec.js index 88c69f0..07ea675 100644 --- a/packages/tao/src/Kernel.spec.js +++ b/packages/tao/src/Kernel.spec.js @@ -981,14 +981,14 @@ describe('Kernel is the base entry point of execution for a tao.js app', () => { const rejectHandlers = postResolveHandlers.get(rejectOnAc.key); // Assert expect(triggerHandlers).toBeDefined(); - expect(triggerHandlers.inlineHandlers).toBeInstanceOf(Set); - expect(triggerHandlers.inlineHandlers.size).toBe(1); + expect(triggerHandlers.inlineHandlers).toBeIterable(true); + expect(Array.from(triggerHandlers.inlineHandlers).length).toBe(1); expect(resolveHandlers).toBeDefined(); - expect(resolveHandlers.inlineHandlers).toBeInstanceOf(Set); - expect(resolveHandlers.inlineHandlers.size).toBe(0); + expect(resolveHandlers.inlineHandlers).toBeIterable(true); + expect(Array.from(resolveHandlers.inlineHandlers).length).toBe(0); expect(rejectHandlers).toBeDefined(); - expect(rejectHandlers.inlineHandlers).toBeInstanceOf(Set); - expect(rejectHandlers.inlineHandlers.size).toBe(0); + expect(rejectHandlers.inlineHandlers).toBeIterable(true); + expect(Array.from(rejectHandlers.inlineHandlers).length).toBe(0); }); }); });