@@ -121,6 +121,37 @@ describe('IDBExportImport', function() {
121
121
assert . ifError ( e ) ;
122
122
} ) ;
123
123
} ) ;
124
+ it ( 'Should ignore stores that are not present when importing' , function ( done ) {
125
+ const db = new Dexie ( 'MyDB' , { indexedDB : fakeIndexedDB } ) ;
126
+ db . version ( 1 ) . stores ( {
127
+ things : 'id++, thing_name, thing_description' ,
128
+ } ) ;
129
+ db . open ( ) . catch ( function ( e ) {
130
+ console . error ( 'Could not connect. ' + e ) ;
131
+ } ) ;
132
+
133
+ const thingsToAdd = [ { thing_name : 'First thing' , thing_description : 'This is the first thing' } ,
134
+ { thing_name : 'Second thing' , thing_description : 'This is the second thing' } ] ;
135
+ db . things . bulkAdd ( thingsToAdd ) . then ( function ( ) {
136
+ const idbDB = db . backendDB ( ) ; // get native IDBDatabase object from Dexie wrapper
137
+ IDBExportImport . importFromJsonString ( idbDB , '{"other":[' +
138
+ '{"thing_name":"First thing","thing_description":"This is the first thing","id":1},' +
139
+ '{"thing_name":"Second thing","thing_description":"This is the second thing","id":2}]}' , function ( err ) {
140
+ assert . ifError ( err ) ;
141
+ console . log ( 'Imported data successfully' ) ;
142
+
143
+ IDBExportImport . clearDatabase ( idbDB , ( ) => {
144
+ IDBExportImport . importFromJsonString ( idbDB , '{"other": []}' , function ( err ) {
145
+ assert . ifError ( err ) ;
146
+ console . log ( 'Imported data successfully' ) ;
147
+ done ( ) ;
148
+ } ) ;
149
+ } ) ;
150
+ } ) ;
151
+ } ) . catch ( Dexie . BulkError , function ( e ) {
152
+ assert . ifError ( e ) ;
153
+ } ) ;
154
+ } ) ;
124
155
it ( 'Should import and export the database with empty keys' , function ( done ) {
125
156
const db = new Dexie ( 'myDB' , { indexedDB : fakeIndexedDB } ) ;
126
157
db . version ( 1 ) . stores ( {
0 commit comments