jest-environment import { WebSQLAdapter } from "../src/storage/adapters/sqlite/WebSQLAdapter" ; import { ModelSchema } from "../src/ModelSchema" ; import { readFileSync } from "fs" ; import { LocalStorage } from "../src" ; const openDatabase = require ( "websql" ) ; let db ; let model ; let adapter ; let storage ; const schema = JSON . parse ( readFileSync ( `${ __dirname }/schema.json` ) . toString ( ) ) ; window . openDatabase = ( name , version , description , size , callback ) => { db = openDatabase ( ":memory:" , version , description , size , callback ) ; return db ; } ; describe ( "sqlite test suite" , ( ) => { afterAll ( ( ) => { db . close ( ) ; } ) ; test ( "it should create a store" , async ( ) => { adapter = new WebSQLAdapter ( "offixdb" , 1 ) ; storage = new LocalStorage ( adapter ) ; model = new ModelSchema < any > ( schema . Test ) ; storage . adapter . addStore ( model ) ; await adapter . createStores ( ) ; const stores = await storage . adapter . getStoreNames ( ) ; expect ( stores ) . toContain ( model . getStoreName ( ) ) ; } ) ; test ( "it should create a store and remove old store" , async ( ) => { adapter = new WebSQLAdapter ( "offixdb" , 1 ) ; storage = new LocalStorage ( adapter ) ; const oldModel = model ; model = new ModelSchema < any > ( schema . Something ) ; storage . adapter . addStore ( model ) ; await adapter . createStores ( ) ; const stores = await storage . adapter . getStoreNames ( ) ; expect ( stores ) . toContain ( model . getStoreName ( ) ) ; expect ( stores ) . not . toContain ( oldModel . getStoreName ( ) ) ; } ) ; } ) ;