@@ -11,8 +11,11 @@ const app = loopback()
1111// import our mixin.
1212require ( '../lib' ) ( app )
1313
14- // Connect to db.
15- const dbConnector = loopback . memory ( )
14+ // Create datasource.
15+ const dbConnector = loopback . createDataSource ( {
16+ connector : loopback . Memory ,
17+ file : 'db.json' ,
18+ } )
1619
1720const now = new Date ( )
1821
@@ -49,6 +52,10 @@ describe('loopback computed property', function() {
4952
5053 lt . beforeEach . withApp ( app )
5154
55+ before ( function ( ) {
56+ return Item . destroyAll ( )
57+ } )
58+
5259 before ( function ( done ) {
5360 new lt . TestDataBuilder ( )
5461 . define ( 'itemOne' , Item , {
@@ -80,4 +87,23 @@ describe('loopback computed property', function() {
8087 expect ( this . itemOne . promised ) . to . equal ( 'Item 1: As promised I get back to you!' )
8188 expect ( this . itemTwo . promised ) . to . equal ( 'Item 2: As promised I get back to you!' )
8289 } )
90+
91+ it ( 'should not store the computed property' , function ( ) {
92+ return this . itemOne . updateAttributes ( { readonly : false } )
93+ . then ( item => {
94+ /* eslint global-require: 0 */
95+ const db = require ( '../db.json' )
96+ const itemFromDb = JSON . parse ( db . models . item [ item . id ] )
97+
98+ expect ( item ) . to . have . property ( 'readonly' , true )
99+ expect ( item ) . to . have . property ( 'requestedAt' )
100+ expect ( item ) . to . have . property ( 'promised' )
101+
102+ expect ( itemFromDb ) . to . have . property ( 'id' , item . id )
103+ expect ( itemFromDb ) . to . have . property ( 'name' , 'Item 1' )
104+ expect ( itemFromDb ) . to . not . have . property ( 'readonly' )
105+ expect ( itemFromDb ) . to . not . have . property ( 'requestedAt' )
106+ expect ( itemFromDb ) . to . not . have . property ( 'promised' )
107+ } )
108+ } )
83109} )
0 commit comments