Event Listening Matchers
Used to verify that the invocation of a spy correctly listened for an event.
Example
The following spec will pass because the expected listeners were set up.
Production code:
initComponent: function () {
this.addListener({
activate: this.onViewActivate,
deactivate: this.onViewDeactivate
});
}
Test suite:
describe('initComponent', function () {
beforeEach(function () {
view.addListener = jasmine.createSpy('addListener');
view.initComponent();
});
it('should listen for activate event using onViewActivate', function () {
expect(view.addListener).toHaveAddedListener({
event: 'activate',
listener: view.onViewActivate
});
})
it('should listen for deactivate event', function () {
expect(view.addListener).toHaveAddedListener('deactivate');
})
});
Matchers
toHaveControlled
Passes if any call to spy
x controlled the event name
y.
expect(x).toHaveControlled(y);
Passes if any call to spy
x controlled the event name
y using optional listener
z and string or regex selector
s.
expect(x).toHaveControlled({
event: y,
listener: z,
selector: s
});
toHaveAddedListener
Passes if any call to spy
x added a listener for the event name
y.
expect(x).toHaveAddedListener(y);
Passes if any call to spy
x added a listener for the event name
y using listener
z.
expect(x).toHaveAddedListener({
event: y,
listener: z
});
toHaveRemovedListener
Passes if any call to spy
x removed a listener for the event name
y.
expect(x).toHaveRemovedListener(y);
Passes if any call to spy
x removed a listener for the event name
y using listener
z.
expect(x).toHaveRemovedListener({
event: y,
listener: z
});
toHaveAddedManagedListener
Passes if any call to spy
x added a managed listener for the event name
y.
expect(x).toHaveAddedManagedListener(y);
Passes if any call to spy
x added a managed listener for the event name
y using listener
z.
expect(x).toHaveAddedManagedListener({
event: y,
listener: z
});
toHaveRemovedManagedListener
Passes if any call to spy
x removed a managed listener for the event name
y.
expect(x).toHaveRemovedManagedListener(y);
Passes if any call to spy
x removed a managed listener for the event name
y using listener
z.
expect(x).toHaveRemovedManagedListener({
event: y,
listener: z
});
Obsolete
The following matchers are obsolete and have been removed from Ext Spec 2.0.0. The following information is available for posterity.
toHaveBoundEvent
Passes if the most recent call to spy
x bound the event
y to listener
z.
expect(x).toHaveBoundEvent(y, z);
Passes if call
i to spy
x bound the event
y to listener
z.
expect(x).toHaveBoundEvent(y, z, i);
Note: Spies must be named on, addListener, mon or addManagedListener.
toHaveUnboundEvent
Passes if the most recent call to spy
x unbound the event
y from listener
z.
expect(x).toHaveUnboundEvent(y, z);
Passes if call
i to spy
x unbound the event
y from listener
z.
expect(x).toHaveUnboundEvent(y, z, i);
Note: Spies must be named un, removeListener, mun or removeManagedListener.
toHaveControlledEvent
Passes if the most recent call to spy
x controlled event
y with listener
z.
expect(x).toHaveControlledEvent(y, z);
Passes if the most recent call to spy
x controlled event
y with listener
z using component query selector
s.
expect(x).toHaveControlledEvent(y, z, s);
Passes if call
i to spy
x controlled event
y with listener
z using component query selector
s.
expect(x).toHaveControlledEvent(y, z, s, i);
Note: Spy must be named control.