Unit testing Routers

edited October 2013 in Enyo 2.4
I'm trying to unit test my Router controller but I can't seem to find the enyo.instance so that I can spy on my changing function. There are objects for the router in my enyo.applications application object in the controllers and $ blocks. However, they are enyoConstructors. How do I get a handle on the actual router object so that I can spyOn it's methods?


  • edited August 2013
    The "enyoConstructor" is the debugger being not helpful. Those are really the instances of the objects, it's just that the actual constructor method that's returned from enyo.kind happens to get that name due to how we generate it.
  • Thanks Ben. That's helpful to know.
  • Figured it out...
    My spy was having trouble because the function on the Router controller is never called directly. That meant the spy was not wrapped around what actually gets called. The Routers _execHandler is called instead and it runs the function via reference.

    In order to do the test, I wrapped the spy around the _execHandler, and checked the displayName of the handler parameter. That value matches the function I expect to be running.
    var spy = spyOn(home.$.routes, '_execHandler').andReturn();
    This is the function signature from the Router:
    _execHandler: function (context, handler, args, route)
    This is the handler parameter for my call:
    handler: function (route) {
      _inherited: undefined
      arguments: null
      caller: null
      displayName: "Routes.changeScreen()"
      length: 1
      name: ""
    Hopefully this will help someone else down the line.
Sign In or Register to comment.