This project is read-only.

Spy Configuration

Many of the Ext Spec spy helpers accept a configuration parameter. This nested configuration allows complex testing scenarios to be setup in a way that should be familiar to Ext JS developers.

In it's simplest form, the configuration is just an array literal containing the spy names to create. This form is more or less exactly the same as jasmine.createSpyObj.
var panelA = ExtSpec.Jasmine.createSpyObject(['addCls', 'removeCls', 'getEl']),
    panelB = jasmine.createSpyObj('panelB', ['addCls', 'removeCls', 'getEl']);
However, if some of these methods should return spy objects of their own (i.e. method chaining), this would normally require all spy objects to be created and assigned manually (and usually in reverse order).
var parentEl = jasmine.createSpyObj('parent', ['addCls']),
    el = jasmine.createSpyObj('el', ['down', 'parent']),
    panel = jasmine.createSpyObj('spyObj', ['addCls', 'removeCls', 'getEl']);

The Ext Spec configuration version of this could look like this:
var panel = ExtSpec.Jasmine.createSpyObject(['addCls', 'removeCls', {
    name: 'getEl',
    value: ['down', {
        name: 'parent',
        value: ['addCls']
The above introduces more lines, but is significantly less keystrokes. This reduction in plumbing improves as the context becomes more complex.


Ext Spec requires the list of spies to be either strings, configuration objects or a combination of both. Configurations must contain a name and optionally a value and / or action in the form:
    name: 'methodName',
    value: ['subMethod1', 'subMethod2'],
    action: 'spy'
Supported actions are:
  • call: equivalent of andCallThrough()
  • fake: equivalent of andCallFake()
  • spy: equivalent of andReturn(jasmine.createSpyObj())
  • return: equivalent of andReturn()
  • object: equivalent of target[name] = jasmine.createSpyObj()
  • property: equivalent of target[name] = value
  • fluent: equivalent of andReturn(target)
  • none: do nothing
If unspecified, the return action is assumed unless the value is a:
  • function: assume fake
  • array: assume spy
  • undefined: assume none

Last edited May 3, 2013 at 11:19 AM by Qube, version 8


No comments yet.