github.com/outbrain/consul@v1.4.5/ui-v2/tests/unit/utils/model/writable-test.js (about) 1 import writable from 'consul-ui/utils/model/writable'; 2 import { module, test } from 'qunit'; 3 4 module('Unit | Utility | model/writable'); 5 6 test('it correctly marks attrs as serialize:true|false', function(assert) { 7 const yes = { 8 Props: true, 9 That: true, 10 Should: true, 11 Be: true, 12 Writable: true, 13 }; 14 const no = { 15 Others: true, 16 Read: true, 17 Only: true, 18 }; 19 const expectedYes = Object.keys(yes); 20 const expectedNo = Object.keys(no); 21 const model = { 22 eachAttribute: function(cb) { 23 expectedYes.concat(expectedNo).forEach(function(item) { 24 cb(item, {}); // we aren't testing the meta here, just use the same api 25 }); 26 }, 27 }; 28 let attrs = writable(model, Object.keys(yes)); 29 const actualYes = Object.keys(attrs).filter(item => attrs[item].serialize); 30 const actualNo = Object.keys(attrs).filter(item => !attrs[item].serialize); 31 assert.deepEqual(actualYes, expectedYes, 'writable props are marked as serializable'); 32 assert.deepEqual(actualNo, expectedNo, 'writable props are marked as not serializable'); 33 attrs = writable(model, Object.keys(yes), { 34 Props: { 35 another: 'property', 36 }, 37 }); 38 assert.equal( 39 attrs.Props.another, 40 'property', 41 'previous attrs objects can be passed without being overwritten' 42 ); 43 });