it('should not fire if `silent = true` is given when calling `set` method', function () { var model = new Model(); var handler = jasmine.createSpy(); model.on('change', handler); model.set('x', 1, { silent: true }); expect(handler).not.toHaveBeenCalled(); });
it('should have a `type` property with value **change** in its event object', function () { var model = new Model(); var handler = jasmine.createSpy(); model.on('change', handler); model.set('x', 1); expect(handler.calls.mostRecent().args[0].type).toBe('change'); });
it('should not fire when set a value with the same value as its previous value', function () { var model = new Model({ x: 1 }); var handler = jasmine.createSpy(); model.on('change', handler); model.set('x', 1); expect(handler).not.toHaveBeenCalled(); });
it('should have a `changes` array in its event object', function () { var model = new Model(); var handler = jasmine.createSpy(); model.on('change', handler); model.set('x', 1); expect(handler.calls.mostRecent().args[0].changes).toBeOfType('array'); });
it('should fire a `change` event when calling `set` method to add or update a property', function () { var model = new Model(); var handler = jasmine.createSpy(); model.on('change', handler); model.set('x', 1); expect(handler).toHaveBeenCalled(); });
it('should have a `newValue` property in its change record', function () { var model = new Model(); var handler = jasmine.createSpy(); model.on('change', handler); model.set('x', 1); var record = handler.calls.mostRecent().args[0].changes[0]; expect(record.hasOwnProperty('newValue')).toBe(true); });
it('should have a `type` property in its change record', function () { var model = new Model(); var handler = jasmine.createSpy(); model.on('change', handler); model.set('x', 1); var record = handler.calls.mostRecent().args[0].changes[0]; expect(record.type).toBeOfType('string'); });
it('should fire with type **change** when updating a property', function () { var model = new Model({ x: 1 }); var handler = jasmine.createSpy(); model.on('change', handler); var value = {}; model.set('x', value); var record = handler.calls.mostRecent().args[0].changes[0]; expect(record.type).toBe('change'); expect(record.newValue).toBe(value); expect(record.oldValue).toBe(1); });
it('should fire with type **add** when adding a property', function () { var model = new Model(); var handler = jasmine.createSpy(); model.on('change', handler); var value = {}; model.set('x', value); var record = handler.mostRecentCall.args[0].changes[0]; expect(record.type).toBe('add'); expect(record.newValue).toBe(value); expect(record.oldValue).toBeUndefined(); });
it('should return the given value', function () { var model = new Model(); var value = {}; var returnValue = model.set('x', value); expect(returnValue).toBe(value); });
it('should change the value if a property exists', function () { var model = new Model({ x: 1 }); var value = {}; model.set('x', value); expect(model.get('x')).toBe(value); });
it('should be able to add a property', function () { var model = new Model(); var value = {}; model.set('x', value); expect(model.get('x')).toBe(value); });
it('should not return its stored context directly', function () { var model = new Model({ x: 1 }); var value = model.valueOf(); model.set('y', 1); expect(value.y).toBeUndefined(); });
it('should return the given extension object', function () { var model = new Model(); var value = { foo: 1, bar: 2 }; var returnValue = model.set('x', value); expect(returnValue).toBe(value); });
exports.createModel = function () { var Model = require('er/Model'); var model = new Model(); model.set('indexURL', require('er/config').indexURL); return model; };