|
|
@@ -3,11 +3,11 @@
|
|
|
* For licensing, see LICENSE.md.
|
|
|
*/
|
|
|
|
|
|
-/* globals describe, it, expect, beforeEach, bender */
|
|
|
+/* globals describe, it, expect, beforeEach, bender, sinon */
|
|
|
|
|
|
'use strict';
|
|
|
|
|
|
-var modules = bender.amd.require( 'mvc/model' );
|
|
|
+var modules = bender.amd.require( 'mvc/model', 'eventinfo' );
|
|
|
|
|
|
var car;
|
|
|
|
|
|
@@ -71,5 +71,44 @@ describe( 'Model', function() {
|
|
|
wheels: 4
|
|
|
} );
|
|
|
} );
|
|
|
+
|
|
|
+ it( 'should fire "change"', function() {
|
|
|
+ var EventInfo = modules.eventinfo;
|
|
|
+
|
|
|
+ var spy = sinon.spy();
|
|
|
+ var spyColor = sinon.spy();
|
|
|
+ var spyYear = sinon.spy();
|
|
|
+ var spyWheels = sinon.spy();
|
|
|
+
|
|
|
+ car.on( 'change', spy );
|
|
|
+ car.on( 'change:color', spyColor );
|
|
|
+ car.on( 'change:year', spyYear );
|
|
|
+ car.on( 'change:wheels', spyWheels );
|
|
|
+
|
|
|
+ // Set property in all possible ways.
|
|
|
+ car.color = 'blue';
|
|
|
+ car.set( { year: 2003 } );
|
|
|
+ car.set( 'wheels', 4 );
|
|
|
+
|
|
|
+ // Check number of calls.
|
|
|
+ sinon.assert.calledThrice( spy );
|
|
|
+ sinon.assert.calledOnce( spyColor );
|
|
|
+ sinon.assert.calledOnce( spyYear );
|
|
|
+ sinon.assert.calledOnce( spyWheels );
|
|
|
+
|
|
|
+ // Check context.
|
|
|
+ sinon.assert.alwaysCalledOn( spy, car );
|
|
|
+ sinon.assert.calledOn( spyColor, car );
|
|
|
+ sinon.assert.calledOn( spyYear, car );
|
|
|
+ sinon.assert.calledOn( spyWheels, car );
|
|
|
+
|
|
|
+ // Check params.
|
|
|
+ sinon.assert.calledWithExactly( spy, sinon.match.instanceOf( EventInfo ), car, 'color', 'blue', 'red' );
|
|
|
+ sinon.assert.calledWithExactly( spy, sinon.match.instanceOf( EventInfo ), car, 'year', 2003, 2015 );
|
|
|
+ sinon.assert.calledWithExactly( spy, sinon.match.instanceOf( EventInfo ), car, 'wheels', 4, sinon.match.typeOf( 'undefined' ) );
|
|
|
+ sinon.assert.calledWithExactly( spyColor, sinon.match.instanceOf( EventInfo ), car, 'blue', 'red' );
|
|
|
+ sinon.assert.calledWithExactly( spyYear, sinon.match.instanceOf( EventInfo ), car, 2003, 2015 );
|
|
|
+ sinon.assert.calledWithExactly( spyWheels, sinon.match.instanceOf( EventInfo ), car, 4, sinon.match.typeOf( 'undefined' ) );
|
|
|
+ } );
|
|
|
} );
|
|
|
} );
|