model.js 19 KB

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