model.js 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709
  1. /**
  2. * @license Copyright (c) 2003-2015, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. 'use strict';
  6. const modules = bender.amd.require( 'model', 'eventinfo', 'ckeditorerror' );
  7. let Car, car;
  8. bender.tools.createSinonSandbox();
  9. describe( 'Model', () => {
  10. beforeEach( 'Create a test model instance', () => {
  11. const Model = modules.model;
  12. Car = class extends Model {};
  13. car = new Car( {
  14. color: 'red',
  15. year: 2015
  16. } );
  17. } );
  18. //////////
  19. it( 'should set _attributes on creation', () => {
  20. expect( car._attributes ).to.deep.equal( {
  21. color: 'red',
  22. year: 2015
  23. } );
  24. } );
  25. it( 'should get correctly after set', () => {
  26. car.color = 'blue';
  27. expect( car.color ).to.equal( 'blue' );
  28. expect( car._attributes.color ).to.equal( 'blue' );
  29. } );
  30. it( 'should get correctly after setting _attributes', () => {
  31. car._attributes.color = 'blue';
  32. expect( car.color ).to.equal( 'blue' );
  33. } );
  34. it( 'should add properties on creation', () => {
  35. let car = new Car( null, {
  36. prop: 1
  37. } );
  38. expect( car ).to.have.property( 'prop' ).to.equal( 1 );
  39. } );
  40. //////////
  41. describe( 'set', () => {
  42. it( 'should work when passing an object', () => {
  43. car.set( {
  44. color: 'blue', // Override
  45. wheels: 4,
  46. seats: 5
  47. } );
  48. expect( car._attributes ).to.deep.equal( {
  49. color: 'blue',
  50. year: 2015,
  51. wheels: 4,
  52. seats: 5
  53. } );
  54. } );
  55. it( 'should work when passing a key/value pair', () => {
  56. car.set( 'color', 'blue' );
  57. car.set( 'wheels', 4 );
  58. expect( car._attributes ).to.deep.equal( {
  59. color: 'blue',
  60. year: 2015,
  61. wheels: 4
  62. } );
  63. } );
  64. it( 'should fire the "change" event', () => {
  65. const EventInfo = modules.eventinfo;
  66. let spy = sinon.spy();
  67. let spyColor = sinon.spy();
  68. let spyYear = sinon.spy();
  69. let spyWheels = sinon.spy();
  70. car.on( 'change', spy );
  71. car.on( 'change:color', spyColor );
  72. car.on( 'change:year', spyYear );
  73. car.on( 'change:wheels', spyWheels );
  74. // Set property in all possible ways.
  75. car.color = 'blue';
  76. car.set( { year: 2003 } );
  77. car.set( 'wheels', 4 );
  78. // Check number of calls.
  79. sinon.assert.calledThrice( spy );
  80. sinon.assert.calledOnce( spyColor );
  81. sinon.assert.calledOnce( spyYear );
  82. sinon.assert.calledOnce( spyWheels );
  83. // Check context.
  84. sinon.assert.alwaysCalledOn( spy, car );
  85. sinon.assert.calledOn( spyColor, car );
  86. sinon.assert.calledOn( spyYear, car );
  87. sinon.assert.calledOn( spyWheels, car );
  88. // Check params.
  89. sinon.assert.calledWithExactly( spy, sinon.match.instanceOf( EventInfo ), 'color', 'blue', 'red' );
  90. sinon.assert.calledWithExactly( spy, sinon.match.instanceOf( EventInfo ), 'year', 2003, 2015 );
  91. sinon.assert.calledWithExactly( spy, sinon.match.instanceOf( EventInfo ), 'wheels', 4, sinon.match.typeOf( 'undefined' ) );
  92. sinon.assert.calledWithExactly( spyColor, sinon.match.instanceOf( EventInfo ), 'blue', 'red' );
  93. sinon.assert.calledWithExactly( spyYear, sinon.match.instanceOf( EventInfo ), 2003, 2015 );
  94. sinon.assert.calledWithExactly( spyWheels, sinon.match.instanceOf( EventInfo ), 4, sinon.match.typeOf( 'undefined' ) );
  95. } );
  96. it( 'should not fire the "change" event for the same attribute value', () => {
  97. let spy = sinon.spy();
  98. let spyColor = sinon.spy();
  99. car.on( 'change', spy );
  100. car.on( 'change:color', spyColor );
  101. // Set the "color" property in all possible ways.
  102. car.color = 'red';
  103. car.set( 'color', 'red' );
  104. car.set( { color: 'red' } );
  105. sinon.assert.notCalled( spy );
  106. sinon.assert.notCalled( spyColor );
  107. } );
  108. it( 'should throw when overriding already existing property', () => {
  109. const CKEditorError = modules.ckeditorerror;
  110. car.normalProperty = 1;
  111. expect( () => {
  112. car.set( 'normalProperty', 2 );
  113. } ).to.throw( CKEditorError, /^model-set-cannot-override/ );
  114. expect( car ).to.have.property( 'normalProperty', 1 );
  115. } );
  116. it( 'should throw when overriding already existing property (in the prototype)', () => {
  117. const CKEditorError = modules.ckeditorerror;
  118. const Model = modules.model;
  119. class Car extends Model {
  120. method() {}
  121. }
  122. car = new Car();
  123. expect( () => {
  124. car.set( 'method', 2 );
  125. } ).to.throw( CKEditorError, /^model-set-cannot-override/ );
  126. expect( car.method ).to.be.a( 'function' );
  127. } );
  128. } );
  129. describe( 'extend', () => {
  130. it( 'should create new Model based classes', () => {
  131. const Model = modules.model;
  132. class Truck extends Car {}
  133. let truck = new Truck();
  134. expect( truck ).to.be.an.instanceof( Car );
  135. expect( truck ).to.be.an.instanceof( Model );
  136. } );
  137. } );
  138. describe( 'bind', () => {
  139. let Model, EventInfo, CKEditorError;
  140. beforeEach( () => {
  141. Model = modules.model;
  142. EventInfo = modules.eventinfo;
  143. CKEditorError = modules.ckeditorerror;
  144. } );
  145. it( 'should chain for a single attribute', () => {
  146. expect( car.bind( 'color' ) ).to.contain.keys( 'to' );
  147. } );
  148. it( 'should chain for multiple attributes', () => {
  149. expect( car.bind( 'color', 'year' ) ).to.contain.keys( 'to' );
  150. } );
  151. it( 'should chain for nonexistent attributes', () => {
  152. expect( car.bind( 'nonexistent' ) ).to.contain.keys( 'to' );
  153. } );
  154. it( 'should throw when attributes are not strings', () => {
  155. expect( () => {
  156. car.bind();
  157. } ).to.throw( CKEditorError, /model-bind-wrong-attrs/ );
  158. expect( () => {
  159. car.bind( new Date() );
  160. } ).to.throw( CKEditorError, /model-bind-wrong-attrs/ );
  161. expect( () => {
  162. car.bind( 'color', new Date() );
  163. } ).to.throw( CKEditorError, /model-bind-wrong-attrs/ );
  164. } );
  165. it( 'should throw when the same attribute is used than once', () => {
  166. expect( () => {
  167. car.bind( 'color', 'color' );
  168. } ).to.throw( CKEditorError, /model-bind-duplicate-attrs/ );
  169. } );
  170. it( 'should throw when binding the same attribute more than once', () => {
  171. expect( () => {
  172. car.bind( 'color' );
  173. car.bind( 'color' );
  174. } ).to.throw( CKEditorError, /model-bind-rebind/ );
  175. } );
  176. describe( 'to', () => {
  177. it( 'should chain', () => {
  178. const returned = car.bind( 'color' ).to( new Model( { color: 'red' } ) );
  179. expect( returned ).to.have.property( 'to' );
  180. expect( returned ).to.have.property( 'as' );
  181. } );
  182. it( 'should chain multiple times', () => {
  183. const returned = car.bind( 'color' )
  184. .to( new Model( { color: 'red' } ) )
  185. .to( new Model( { color: 'red' } ) )
  186. .to( new Model( { color: 'red' } ) );
  187. expect( returned ).to.have.property( 'to' );
  188. expect( returned ).to.have.property( 'as' );
  189. } );
  190. it( 'should throw when .to() model is not Model', () => {
  191. expect( () => {
  192. car.bind( 'color' ).to();
  193. } ).to.throw( CKEditorError, /model-bind-to-wrong-model/ );
  194. expect( () => {
  195. car.bind( 'year' ).to( 'it\'s not a model' );
  196. } ).to.throw( CKEditorError, /model-bind-to-wrong-model/ );
  197. } );
  198. it( 'should throw when attributes are not strings', () => {
  199. expect( () => {
  200. car.bind( 'color' ).to( new Model(), new Date() );
  201. } ).to.throw( CKEditorError, /model-bind-to-wrong-attrs/ );
  202. expect( () => {
  203. car = new Car( { color: 'red' } );
  204. car.bind( 'color' ).to( new Model(), 'color', new Date() );
  205. } ).to.throw( CKEditorError, /model-bind-to-wrong-attrs/ );
  206. } );
  207. it( 'should throw when a number of attributes does not match', () => {
  208. expect( () => {
  209. const vehicle = new Car();
  210. vehicle.bind( 'color', 'year' ).to( car, 'color' );
  211. } ).to.throw( CKEditorError, /model-bind-to-attrs-length/ );
  212. expect( () => {
  213. const vehicle = new Car();
  214. vehicle.bind( 'color' ).to( car, 'color', 'year' );
  215. } ).to.throw( CKEditorError, /model-bind-to-attrs-length/ );
  216. expect( () => {
  217. const vehicle = new Car();
  218. vehicle.bind( 'color' ).to( car, 'color' ).to( car, 'color', 'year' );
  219. } ).to.throw( CKEditorError, /model-bind-to-attrs-length/ );
  220. } );
  221. it( 'should throw when no attribute specified and those from bind() don\'t exist in to() model', () => {
  222. const vehicle = new Car();
  223. expect( () => {
  224. vehicle.bind( 'color' ).to( car, 'nonexistent in car' );
  225. } ).to.throw( CKEditorError, /model-bind-to-missing-attr/ );
  226. expect( () => {
  227. vehicle.bind( 'nonexistent in car' ).to( car );
  228. } ).to.throw( CKEditorError, /model-bind-to-missing-attr/ );
  229. } );
  230. it( 'should throw when to() more than once and multiple attributes', () => {
  231. const car1 = new Car( { color: 'red', year: 2000 } );
  232. const car2 = new Car( { color: 'red', year: 2000 } );
  233. expect( () => {
  234. const vehicle = new Car();
  235. vehicle.bind( 'color', 'year' ).to( car1 ).to( car2 );
  236. } ).to.throw( CKEditorError, /model-bind-to-chain-multiple-attrs/ );
  237. expect( () => {
  238. const vehicle = new Car();
  239. vehicle.bind( 'color', 'year' ).to( car1, 'color', 'year' ).to( car2, 'color', 'year' );
  240. } ).to.throw( CKEditorError, /model-bind-to-chain-multiple-attrs/ );
  241. } );
  242. it( 'should set new model attributes', () => {
  243. const car = new Car( { color: 'green', year: 2001, type: 'pickup' } );
  244. const vehicle = new Car( { 'not involved': true } );
  245. vehicle.bind( 'color', 'year', 'type' ).to( car );
  246. expect( vehicle._attributes ).to.have.keys( 'color', 'year', 'type', 'not involved' );
  247. } );
  248. it( 'should work when no attribute specified #1', () => {
  249. const vehicle = new Car();
  250. vehicle.bind( 'color' ).to( car );
  251. assertBinding( vehicle,
  252. { color: car.color, year: undefined },
  253. [
  254. [ car, { color: 'blue', year: 1969 } ]
  255. ],
  256. { color: 'blue', year: undefined }
  257. );
  258. } );
  259. it( 'should work for a single attribute', () => {
  260. const vehicle = new Car();
  261. vehicle.bind( 'color' ).to( car, 'color' );
  262. assertBinding( vehicle,
  263. { color: car.color, year: undefined },
  264. [
  265. [ car, { color: 'blue', year: 1969 } ]
  266. ],
  267. { color: 'blue', year: undefined }
  268. );
  269. } );
  270. it( 'should work for multiple attributes', () => {
  271. const vehicle = new Car();
  272. vehicle.bind( 'color', 'year' ).to( car, 'color', 'year' );
  273. assertBinding( vehicle,
  274. { color: car.color, year: car.year },
  275. [
  276. [ car, { color: 'blue', year: 1969 } ]
  277. ],
  278. { color: 'blue', year: 1969 }
  279. );
  280. } );
  281. it( 'should work for attributes that don\'t exist in the model', () => {
  282. const vehicle = new Car();
  283. vehicle.bind( 'nonexistent in vehicle' ).to( car, 'color' );
  284. assertBinding( vehicle,
  285. { 'nonexistent in vehicle': car.color, color: undefined },
  286. [
  287. [ car, { color: 'blue', year: 1969 } ]
  288. ],
  289. { 'nonexistent in vehicle': 'blue', color: undefined }
  290. );
  291. } );
  292. it( 'should work when using the same attribute name more than once', () => {
  293. const vehicle = new Car();
  294. vehicle.bind( 'color', 'year' ).to( car, 'year', 'year' );
  295. assertBinding( vehicle,
  296. { color: car.year, year: car.year },
  297. [
  298. [ car, { color: 'blue', year: 1969 } ]
  299. ],
  300. { color: 1969, year: 1969 }
  301. );
  302. } );
  303. it( 'should not throw when binding more than once but no as() afterwards', () => {
  304. const vehicle = new Car();
  305. const car1 = new Car( { color: 'red' } );
  306. const car2 = new Car( { color: 'red' } );
  307. vehicle.bind( 'color' ).to( car1 ).to( car2 );
  308. assertBinding( vehicle,
  309. { color: undefined, year: undefined },
  310. [
  311. [ car, { color: 'blue', year: 1969 } ]
  312. ],
  313. { color: undefined, year: undefined }
  314. );
  315. } );
  316. describe( 'as', () => {
  317. it( 'should not chain', () => {
  318. const car1 = new Car( { year: 1999 } );
  319. const car2 = new Car( { year: 2000 } );
  320. expect(
  321. car.bind( 'year' ).to( car1, 'year' ).to( car2, 'year' ).as( () => {} )
  322. ).to.be.undefined;
  323. } );
  324. it( 'should throw when not a function passed', () => {
  325. const car1 = new Car( { color: 'brown' } );
  326. const car2 = new Car( { color: 'green' } );
  327. expect( () => {
  328. car.bind( 'year' ).to( car1, 'color' ).to( car2, 'color' ).as();
  329. } ).to.throw( CKEditorError, /model-bind-as-wrong-callback/ );
  330. expect( () => {
  331. car.bind( 'color' ).to( car1, 'color' ).to( car2, 'color' ).as( 'not-a-function' );
  332. } ).to.throw( CKEditorError, /model-bind-as-wrong-callback/ );
  333. } );
  334. it( 'should set new model attributes', () => {
  335. const vehicle = new Car();
  336. const car1 = new Car( { type: 'pickup' } );
  337. const car2 = new Car( { type: 'truck' } );
  338. vehicle.bind( 'type' )
  339. .to( car1 )
  340. .to( car2 )
  341. .as( ( col1, col2 ) => col1 + col2 );
  342. expect( vehicle._attributes ).to.have.keys( [ 'type' ] );
  343. } );
  344. it( 'should work for a single attribute #1', () => {
  345. const vehicle = new Car();
  346. const car1 = new Car( { color: 'black' } );
  347. const car2 = new Car( { color: 'brown' } );
  348. vehicle.bind( 'color' )
  349. .to( car1 )
  350. .to( car2 )
  351. .as( ( col1, col2 ) => col1 + col2 );
  352. assertBinding( vehicle,
  353. { color: car1.color + car2.color, year: undefined },
  354. [
  355. [ car1, { color: 'black', year: 1930 } ],
  356. [ car2, { color: 'green', year: 1950 } ]
  357. ],
  358. { color: 'blackgreen', year: undefined }
  359. );
  360. } );
  361. it( 'should work for a single attribute #2', () => {
  362. const vehicle = new Car();
  363. const car1 = new Car( { color: 'black' } );
  364. const car2 = new Car( { color: 'brown' } );
  365. vehicle.bind( 'color' )
  366. .to( car1, 'color' )
  367. .to( car2, 'color' )
  368. .as( ( col1, col2 ) => col1 + col2 );
  369. assertBinding( vehicle,
  370. { color: car1.color + car2.color, year: undefined },
  371. [
  372. [ car1, { color: 'black', year: 1930 } ],
  373. [ car2, { color: 'green', year: 1950 } ]
  374. ],
  375. { color: 'blackgreen', year: undefined }
  376. );
  377. } );
  378. it( 'should work for a single attribute #3', () => {
  379. const vehicle = new Car();
  380. const car1 = new Car( { color: 'black' } );
  381. const car2 = new Car( { color: 'brown' } );
  382. const car3 = new Car( { color: 'yellow' } );
  383. vehicle.bind( 'color' )
  384. .to( car1 )
  385. .to( car2 )
  386. .to( car3 )
  387. .as( ( col1, col2, col3 ) => col1 + col2 + col3 );
  388. assertBinding( vehicle,
  389. { color: car1.color + car2.color + car3.color, year: undefined },
  390. [
  391. [ car1, { color: 'black', year: 1930 } ],
  392. [ car2, { color: 'green', year: 1950 } ]
  393. ],
  394. { color: 'blackgreenyellow', year: undefined }
  395. );
  396. } );
  397. it( 'should work for a single attribute #4', () => {
  398. const vehicle = new Car();
  399. const car1 = new Car( { color: 'black' } );
  400. const car2 = new Car( { lightness: 'bright' } );
  401. const car3 = new Car( { color: 'yellow' } );
  402. vehicle.bind( 'color' )
  403. .to( car1 )
  404. .to( car2, 'lightness' )
  405. .to( car3 )
  406. .as( ( col1, lightness, col3 ) => col1 + lightness + col3 );
  407. assertBinding( vehicle,
  408. { color: car1.color + car2.lightness + car3.color, year: undefined },
  409. [
  410. [ car1, { color: 'black', year: 1930 } ],
  411. [ car2, { color: 'green', year: 1950 } ]
  412. ],
  413. { color: 'blackbrightyellow', year: undefined }
  414. );
  415. } );
  416. } );
  417. } );
  418. } );
  419. describe( 'unbind', () => {
  420. let Model, EventInfo, CKEditorError;
  421. beforeEach( () => {
  422. Model = modules.model;
  423. EventInfo = modules.eventinfo;
  424. CKEditorError = modules.ckeditorerror;
  425. } );
  426. it( 'should throw when non-string attribute is passed', () => {
  427. expect( () => {
  428. car.unbind( new Date() );
  429. } ).to.throw( CKEditorError, /model-unbind-wrong-attrs/ );
  430. } );
  431. it( 'should remove all bindings', () => {
  432. const vehicle = new Car();
  433. vehicle.bind( 'color', 'year' ).to( car, 'color', 'year' );
  434. vehicle.unbind();
  435. assertBinding( vehicle,
  436. { color: 'red', year: 2015 },
  437. [
  438. [ car, { color: 'blue', year: 1969 } ]
  439. ],
  440. { color: 'red', year: 2015 }
  441. );
  442. } );
  443. it( 'should remove bindings of certain attributes', () => {
  444. const vehicle = new Car();
  445. const car = new Car( { color: 'red', year: 2000, torque: 160 } );
  446. vehicle.bind( 'color', 'year', 'torque' ).to( car );
  447. vehicle.unbind( 'year', 'torque' );
  448. assertBinding( vehicle,
  449. { color: 'red', year: 2000, torque: 160 },
  450. [
  451. [ car, { color: 'blue', year: 1969, torque: 220 } ]
  452. ],
  453. { color: 'blue', year: 2000, torque: 160 }
  454. );
  455. } );
  456. it( 'should remove bindings of certain attributes, as()', () => {
  457. const vehicle = new Car();
  458. const car1 = new Car( { color: 'red' } );
  459. const car2 = new Car( { color: 'blue' } );
  460. vehicle.bind( 'color' ).to( car1 ).to( car2 ).as( ( c1, c2 ) => c1 + c2 );
  461. vehicle.unbind( 'color' );
  462. assertBinding( vehicle,
  463. { color: 'redblue' },
  464. [
  465. [ car1, { color: 'green' } ],
  466. [ car2, { color: 'violet' } ]
  467. ],
  468. { color: 'redblue' }
  469. );
  470. } );
  471. it( 'should process the internal structure and listeners correctly', () => {
  472. const model = new Model();
  473. const bound1 = new Model( { b1a: 'foo' } );
  474. const bound2 = new Model( { b2b: 42, 'b2c': 'bar' } );
  475. const bound3 = new Model( { b3d: 'baz' } );
  476. model.bind( 'a' ).to( bound1, 'b1a' );
  477. model.bind( 'b', 'c' ).to( bound2, 'b2b', 'b2c' );
  478. model.bind( 'd', 'e' ).to( bound3, 'b3d', 'b3d' );
  479. assertStructure( model,
  480. { a: true, b: true, c: true, d: true, e: true },
  481. [ bound1, bound2, bound3 ],
  482. [
  483. { b1a: [ 'a' ] },
  484. { b2b: [ 'b' ], b2c: [ 'c' ] },
  485. { b3d: [ 'd', 'e' ] }
  486. ]
  487. );
  488. model.unbind( 'c', 'd' );
  489. assertStructure( model,
  490. { a: true, b: true, e: true },
  491. [ bound1, bound2, bound3 ],
  492. [
  493. { b1a: [ 'a' ] },
  494. { b2b: [ 'b' ] },
  495. { b3d: [ 'e' ] }
  496. ]
  497. );
  498. model.unbind( 'b' );
  499. assertStructure( model,
  500. { a: true, e: true },
  501. [ bound1, bound3 ],
  502. [
  503. { b1a: [ 'a' ] },
  504. { b3d: [ 'e' ] }
  505. ]
  506. );
  507. model.unbind();
  508. assertStructure( model, {}, [], [] );
  509. } );
  510. } );
  511. // Syntax given that model `A` is bound to models [`B`, `C`, ...]:
  512. //
  513. // assertBinding( A,
  514. // { initial `A` attributes },
  515. // [
  516. // [ B, { new `B` attributes } ],
  517. // [ C, { new `C` attributes } ],
  518. // ...
  519. // ],
  520. // { `A` attributes after [`B`, 'C', ...] changed }
  521. // );
  522. //
  523. function assertBinding( model, stateBefore, data, stateAfter ) {
  524. let key, pair;
  525. for ( key in stateBefore ) {
  526. expect( model[ key ] ).to.be.equal( stateBefore[ key ] );
  527. }
  528. // Change attributes of bound models.
  529. for ( pair of data ) {
  530. for ( key in pair[ 1 ] ) {
  531. pair[ 0 ][ key ] = pair[ 1 ][ key ];
  532. }
  533. }
  534. for ( key in stateAfter ) {
  535. expect( model[ key ] ).to.be.equal( stateAfter[ key ] );
  536. }
  537. }
  538. function assertStructure( model, expectedBound, expectedModels, expectedBindings ) {
  539. const boundModels = [ ...model._boundTo.keys() ];
  540. // Check model._bound object.
  541. expect( model._bound ).to.be.deep.equal( expectedBound );
  542. // Check model._boundTo models.
  543. expect( boundModels ).to.have.members( expectedModels );
  544. // Check model._listeningTo models.
  545. boundModels.map( boundModel => {
  546. expect( model._listeningTo ).to.have.ownProperty( boundModel._emitterId );
  547. } );
  548. // Check model._boundTo model bindings.
  549. expectedBindings.forEach( ( binding, index ) => {
  550. const bindingKeys = Object.keys( binding );
  551. expect( model._boundTo.get( expectedModels[ index ] ) ).to.have.keys( bindingKeys );
  552. bindingKeys.forEach( k => {
  553. expect( Array.from( model._boundTo.get( expectedModels[ index ] )[ k ] ) )
  554. .to.have.members( binding[ k ] );
  555. } );
  556. } );
  557. }
  558. } );