Resource Matchers

Ext Spec's resource matchers expect that an Ext JS class instance (usually a controller) contains a given model, view, controller, store or ref.

They are particularly valuable assertions for catching renaming errors. For example, the following spec will correctly fail because the "Cargo" store was renamed to "Cargos" without updating the code under test.

stores: ['Cargos'],
// ...
onCargoLoadButtonClick: function () {
    this.getStore('Cargo').load();
}
it('should load the Cargo store', function () {
    var store = jasmine.createSpyObj('store', ['load']);
    controller.getStore = jasmine.createSpy('getStore').andReturn(store);

    controller.onCargoLoadButtonClick();

    expect(controller).toHaveStore('Cargo');
    expect(controller.getStore).toHaveBeenCalled();
    expect(store.load).toHaveBeenCalled();
});

toHaveModel

Passes if instance x contains the model name y.
expect(x).toHaveModel(y);

toHaveView

Passes if instance x contains the view name y.
expect(x).toHaveView(y);

toHaveController

Passes if instance x contains the controller name y.
expect(x).toHaveController(y);

toHaveStore

Passes if instance x contains the store name y.
expect(x).toHaveStore(y);

toHaveRef

Passes if instance x contains the ref name y.
expect(x).toHaveRef(y);

Last edited Sep 7, 2012 at 10:45 AM by Qube, version 3

Comments

No comments yet.