Code coverage report for spec/generic/test.spec.js

Statements: 87.58% (275 / 314)      Branches: 62.5% (5 / 8)      Functions: 56.92% (37 / 65)      Lines: 87.5% (273 / 312)      Ignored: none     

All files » spec/generic/ » test.spec.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 8631 1 1     1 1       1 2 1         1 13 13   13           13           13               1 1   1     1     1         1     1             1 1     1 1 1   1   1     1               1   1 1         1     1 1       1             1   1 1   1   1     1   1             1   1 1 1       1 1 1 1   1         1         1         1         1         1         1         1           1 1           1 1   1 1   1 1   1 1     1           1 1   1 1   1 1   1 1   1 1     1 1       1 1   1 1     1 1       1 1   1 1   1 1   1 1       1 1 1   1 1   1 1 1 1 1   1     1 1     1 1   1     1 1       1 1 1       1     1     1     1     1     1     1     1         1         1   1         1     1         1   1         1     1         1     1         1   1         1     1         1   1         1       1 1   1         2       1     1       1 1 1   1         1         1         1         1         1         1         1             1                 1                 1                         1                 1                 1                     1   1                       1                   1       1 1 1   1         1         1             1             1               1                   1                       1         1 1 1 1           1     1 1 1                           1 1 1 2   1 2     1       1       1       1         1       1 1 1             1 1 1         1     1           1   1           1             1     1                 1 1   1     1 4         1           1 1 1   1         1     1     1         1 1   1       1     1           1 1 1   1     1   1     1           1 1 1         1     1     1 1 1     1 1           1 1 1 1 1     1     1 1 1   1 1       1     1 1         1   1     1 1       1 1 1 1 1   1 1              
Eif (typeof (window) === 'undefined') {
  var loki = require('../../src/lokijs.js');
  var suite = require('../helpers/assert-helpers.js').suite;
}
 
describe('loki', function () {
  var db,
    users,
    jonas;
 
  function docCompare(a, b) {
    if (a.$loki < b.$loki) return -1;
    Eif (a.$loki > b.$loki) return 1;
 
    return 0;
  }
 
  beforeEach(function () {
    db = new loki('test.json');
    users = db.addCollection('user');
 
    users.insert({
      name: 'dave',
      age: 25,
      lang: 'English'
    });
 
    users.insert({
      name: 'joe',
      age: 39,
      lang: 'Italian'
    });
 
    jonas = users.insert({
      name: 'jonas',
      age: 30,
      lang: 'Swedish'
    });
  })
 
 
  describe('core methods', function () {
    it('works', function () {
      // findOne()
      var j = users.findOne({
        'name': 'jonas'
      });
      expect(j.name).toEqual('jonas');
 
      // find()
      var result = users.find({
        'age': {
          '$gt': 29
        }
      });
      expect(result.length).toEqual(2);
 
      // $regex test
      expect(users.find({
        'name': {
          '$regex': /o/
        }
      }).length).toEqual(2);
 
      // insert() : try inserting existing document (should fail), try adding doc with legacy id column
      var collectionLength = users.data.length;
      var objDave = users.findOne({
        'name': 'dave'
      });
      var wasAdded = true;
      try {
        users.insert(objDave);
      } catch (err) {
        wasAdded = false;
      }
      expect(wasAdded).toEqual(false);
 
      // our collections are not strongly typed so lets invent some object that has its 'own' id column
      var legacyObject = {
        id: 999,
        first: 'aaa',
        last: 'bbb',
        city: 'pasadena',
        state: 'ca'
      }
 
      wasAdded = true;
 
      try {
        users.insert(legacyObject);
      } catch (err) {
        wasAdded = false;
      }
 
      expect(wasAdded).toEqual(true);
 
      // remove object so later queries access valid properties on all objects
      Eif (wasAdded) {
        users.remove(legacyObject); // the object itself should have been modified
      }
 
      // update()
      legacyObject = {
        id: 998,
        first: 'aaa',
        last: 'bbb',
        city: 'pasadena',
        state: 'ca'
      }
      var wasUpdated = true;
 
      try {
        users.update(legacyObject);
      } catch (err) {
        wasUpdated = false;
      }
      expect(wasUpdated).toEqual(false);
 
      // remove() - add some bogus object to remove
      var userCount1 = users.data.length;
 
      testObject = {
        first: 'aaa',
        last: 'bbb',
        city: 'pasadena',
        state: 'ca'
      }
 
      users.insert(testObject);
 
      expect(userCount1 + 1).toEqual(users.data.length);
      users.remove(testObject);
      expect(userCount1).toEqual(users.data.length);
    })
  });
 
  describe('calculateRange', function () {
    it('works', function () {
      var eic = db.addCollection('eic');
      eic.ensureIndex('testid');
 
      eic.insert({
        'testid': 1,
        'testString': 'hhh',
        'testFloat': 5.2
      }); //0
      eic.insert({
        'testid': 1,
        'testString': 'aaa',
        'testFloat': 6.2
      }); //1
      eic.insert({
        'testid': 5,
        'testString': 'zzz',
        'testFloat': 7.2
      }); //2
      eic.insert({
        'testid': 6,
        'testString': 'ggg',
        'testFloat': 1.2
      }); //3
      eic.insert({
        'testid': 9,
        'testString': 'www',
        'testFloat': 8.2
      }); //4
      eic.insert({
        'testid': 11,
        'testString': 'yyy',
        'testFloat': 4.2
      }); //5
      eic.insert({
        'testid': 22,
        'testString': 'yyz',
        'testFloat': 9.2
      }); //6
      eic.insert({
        'testid': 23,
        'testString': 'm',
        'testFloat': 2.2
      }); //7
 
      var rset = eic.chain();
      rset.find({
        'testid': 1
      }); // force index to be built
 
      // ranges are order of sequence in index not data array positions
 
      var range = rset.calculateRange('$eq', 'testid', 22);
      expect(range).toEqual([6, 6]);
 
      range = rset.calculateRange('$eq', 'testid', 1);
      expect(range).toEqual([0, 1]);
 
      range = rset.calculateRange('$eq', 'testid', 7);
      expect(range).toEqual([0, -1]);
 
      range = rset.calculateRange('$gte', 'testid', 23);
      expect(range).toEqual([7, 7]);
 
      // reference this new record for future evaluations
      eic.insert({
        'testid': 23,
        'testString': 'bbb',
        'testFloat': 1.9
      });
 
      range = rset.calculateRange('$gte', 'testid', 23);
      expect(range).toEqual([7, 8]);
 
      range = rset.calculateRange('$gte', 'testid', 24);
      expect(range).toEqual([0, -1]);
 
      range = rset.calculateRange('$lte', 'testid', 5);
      expect(range).toEqual([0, 2]);
 
      range = rset.calculateRange('$lte', 'testid', 1);
      expect(range).toEqual([0, 1]);
 
      range = rset.calculateRange('$lte', 'testid', -1);
      expect(range).toEqual([0, -1]);
 
      // add another index on string property
      eic.ensureIndex('testString');
      rset.find({
        'testString': 'asdf'
      }); // force index to be built
 
      range = rset.calculateRange('$lte', 'testString', 'ggg');
      expect(range).toEqual([0, 2]); // includes record added in middle
 
      range = rset.calculateRange('$gte', 'testString', 'm');
      expect(range).toEqual([4, 8]); // offset by 1 because of record in middle
 
      // add some float range evaluations
      eic.ensureIndex('testFloat');
      rset.find({
        'testFloat': '1.1'
      }); // force index to be built
 
      range = rset.calculateRange('$lte', 'testFloat', 1.2);
      expect(range).toEqual([0, 0]);
 
      range = rset.calculateRange('$eq', 'testFloat', 1.111);
      expect(range).toEqual([0, -1]);
 
      range = rset.calculateRange('$eq', 'testFloat', 8.2);
      expect(range).toEqual([7, 7]); // 8th pos
 
      range = rset.calculateRange('$gte', 'testFloat', 1.0);
      expect(range).toEqual([0, 8]); // 8th pos
    })
  });
 
  describe('indexLifecycle', function () {
    it('works', function () {
      var ilc = db.addCollection('ilc');
 
      var hasIdx = ilc.binaryIndices.hasOwnProperty('testid');
      expect(hasIdx).toEqual(false);
 
      ilc.ensureIndex('testid');
      hasIdx = ilc.binaryIndices.hasOwnProperty('testid');
      expect(hasIdx).toEqual(true);
      expect(ilc.binaryIndices.testid.dirty).toEqual(false);
      expect(ilc.binaryIndices.testid.values).toEqual([]);
 
      ilc.insert({
        'testid': 5
      });
      expect(ilc.binaryIndices.testid.dirty).toEqual(true);
      ilc.insert({
        'testid': 8
      });
      expect(ilc.binaryIndices.testid.values).toEqual([]);
      expect(ilc.binaryIndices.testid.dirty).toEqual(true);
 
      ilc.find({
        'testid': 8
      }); // should force index build
      expect(ilc.binaryIndices.testid.dirty).toEqual(false);
      expect(ilc.binaryIndices.testid.values.length).toEqual(2);
    })
  })
 
  describe('indexes', function () {
    it('works', function () {
      var itc = db.addCollection('test', {
        indices: ['testid']
      });
 
      itc.insert({
        'testid': 1
      });
      itc.insert({
        'testid': 2
      });
      itc.insert({
        'testid': 5
      });
      itc.insert({
        'testid': 5
      });
      itc.insert({
        'testid': 9
      });
      itc.insert({
        'testid': 11
      });
      itc.insert({
        'testid': 22
      });
      itc.insert({
        'testid': 22
      });
 
      // lte
      var results = itc.find({
        'testid': {
          '$lte': 1
        }
      });
      expect(results.length).toEqual(1);
 
      results = itc.find({
        'testid': {
          '$lte': 22
        }
      });
      expect(results.length).toEqual(8);
 
      // lt
      results = itc.find({
        'testid': {
          '$lt': 1
        }
      });
      expect(results.length).toEqual(0);
 
      results = itc.find({
        'testid': {
          '$lt': 22
        }
      });
      expect(results.length).toEqual(6);
 
      // eq
      results = itc.find({
        'testid': {
          '$eq': 22
        }
      });
      expect(results.length).toEqual(2);
 
      // gt
      results = itc.find({
        'testid': {
          '$gt': 22
        }
      });
      expect(results.length).toEqual(0);
 
      results = itc.find({
        'testid': {
          '$gt': 5
        }
      });
      expect(results.length).toEqual(4);
 
      // gte
      results = itc.find({
        'testid': {
          '$gte': 5
        }
      });
      expect(results.length).toEqual(6);
 
      results = itc.find({
        'testid': {
          '$gte': 10
        }
      });
      expect(results.length).toEqual(3);
    });
  });
 
  describe('resultSet', function () {
    it('works', function () {
      // Resultset find
      expect(users.chain().find({
        'age': {
          '$gte': 30
        }
      }).where(function (obj) {
        return obj.lang === 'Swedish';
      }).data().length).toEqual(1);
 
      // Resultset offset
      expect(users.chain().offset(1).data().length).toEqual(users.data.length - 1);
 
      // Resultset limit
      expect(users.chain().limit(2).data().length).toEqual(2);
    });
  });
 
  describe('andOrOps', function () {
    it('works', function () {
      var eic = db.addCollection('eic');
 
      eic.insert({
        'testid': 1,
        'testString': 'hhh',
        'testFloat': 5.2
      }); //0
      eic.insert({
        'testid': 1,
        'testString': 'bbb',
        'testFloat': 6.2
      }); //1
      eic.insert({
        'testid': 5,
        'testString': 'zzz',
        'testFloat': 7.2
      }); //2
      eic.insert({
        'testid': 6,
        'testString': 'ggg',
        'testFloat': 1.2
      }); //3
      eic.insert({
        'testid': 9,
        'testString': 'www',
        'testFloat': 8.2
      }); //4
      eic.insert({
        'testid': 11,
        'testString': 'yyy',
        'testFloat': 4.2
      }); //5
      eic.insert({
        'testid': 22,
        'testString': 'bbb',
        'testFloat': 9.2
      }); //6
      eic.insert({
        'testid': 23,
        'testString': 'm',
        'testFloat': 2.2
      }); //7
 
      // coll.find $and
      expect(eic.find({
        '$and': [{
          'testid': 1
        }, {
          'testString': 'bbb'
        }]
      }).length).toEqual(1);
 
      // resultset.find $and
      expect(eic.chain().find({
        '$and': [{
          'testid': 1
        }, {
          'testString': 'bbb'
        }]
      }).data().length).toEqual(1);
 
      // resultset.find explicit operators
      expect(eic.chain().find({
        '$and': [{
          'testid': {
            '$eq': 1
          }
        }, {
          'testFloat': {
            '$gt': 6.0
          }
        }]
      }).data().length).toEqual(1);
 
      // coll.find $or
      expect(eic.find({
        '$or': [{
          'testid': 1
        }, {
          'testString': 'bbb'
        }]
      }).length).toEqual(3);
 
      // resultset.find $or
      expect(eic.chain().find({
        '$or': [{
          'testid': 1
        }, {
          'testString': 'bbb'
        }]
      }).data().length).toEqual(3);
 
      // resultset.find explicit operators
      expect(eic.chain().find({
        '$or': [{
          'testid': 1
        }, {
          'testFloat': {
            '$gt': 7.0
          }
        }]
      }).data().length).toEqual(5);
 
      // add index and repeat final test
      eic.ensureIndex('testid');
 
      expect(eic.chain().find({
        '$and': [{
          'testid': {
            '$eq': 1
          }
        }, {
          'testFloat': {
            '$gt': 6.0
          }
        }]
      }).data().length).toEqual(1);
 
      expect(eic.chain().find({
        '$or': [{
          'testid': 1
        }, {
          'testFloat': {
            '$gt': 7.0
          }
        }]
      }).data().length).toEqual(5);
 
      db.removeCollection('eic');
    });
  });
 
  describe('findOne', function () {
    it('works', function () {
      var eic = db.addCollection('eic');
 
      eic.insert({
        'testid': 1,
        'testString': 'hhh',
        'testFloat': 5.2
      }); //0
      eic.insert({
        'testid': 1,
        'testString': 'bbb',
        'testFloat': 6.2
      }); //1
      eic.insert({
        'testid': 5,
        'testString': 'zzz',
        'testFloat': 7.2
      }); //2
 
      // coll.findOne return type
      it('return type', function () {
        expect(typeof eic.findOne({
          'testid': 1
        })).toEqual('object');
      });
 
      // coll.findOne return match
      it('should match 7.2', function () {
        expect(eic.findOne({
          'testid': 5
        }).testFloat).toEqual(7.2);
 
      });
 
      // findOne with $and op
      it('findOne with $and op', function () {
        expect(eic.findOne({
          '$and': [{
            'testid': 1
          }, {
            'testString': 'bbb'
          }]
        }).testFloat, 6.2);
      });
 
      it('findOne with $or op', function () {
        expect(eic.findOne({
          '$or': [{
            'testid': 2
          }, {
            'testString': 'zzz'
          }]
        }).testFloat).toEqual(7.2);
 
      });
      // findOne with $and op
 
      db.removeCollection('eic');
    })
  })
 
  /* Dynamic View Tests */
  describe('stepEvaluateDocument', function () {
    it('works', function () {
      var view = users.addDynamicView('test');
      var query = {
        'age': {
          '$gt': 24
        }
      };
 
      view.applyFind(query);
 
      // churn evaluateDocuments() to make sure it works right
      jonas.age = 23;
      users.update(jonas);
      it('evaluate documents', function () {
        expect(view.data().length).toEqual(users.data.length - 1);
        jonas.age = 30;
        users.update(jonas);
        expect(view.data().length).toEqual(users.data.length);
        jonas.age = 23;
        users.update(jonas);
        expect(view.data().length).toEqual(users.data.length - 1);
        jonas.age = 30;
        users.update(jonas);
        expect(view.data().length).toEqual(users.data.length);
      });
 
      // assert set equality of docArrays irrelevant of sort/sequence
      var result1 = users.find(query).sort(docCompare);
      var result2 = view.data().sort(docCompare);
      result1.forEach(function (obj) {
        delete obj.meta
      });
      result2.forEach(function (obj) {
        delete obj.meta
      });
 
      it('Result data Equality', function () {
        expect(result1).toEqual(result2);
      });
 
      it('Strict Equality', function () {
        expect(users.find(query) === view.data()).toBeTruthy();
      });
 
      it('View data equality', function () {
        expect(view.resultset).toEqual(view.resultset.copy());
      });
 
      it('View data copy strict equality', function () {
        expect(view.resultset === view.resultset.copy()).toBeFalsy();
      });
 
 
      return view;
    });
  });
 
  describe('stepDynamicViewPersistence', function () {
    it('works', function stepDynamicViewPersistence() {
      var query = {
        'age': {
          '$gt': 24
        }
      };
 
      // set up a persistent dynamic view with sort
      var pview = users.addDynamicView('test2', true);
      pview.applyFind(query);
      pview.applySimpleSort('age');
 
      // the dynamic view depends on an internal resultset
      // the persistent dynamic view also depends on an internal resultdata data array
      // filteredrows should be applied immediately to resultset will be lazily built into resultdata later when data() is called
      it('dynamic view initialization 1', function () {
        expect(pview.resultset.filteredrows.length).toEqual(3);
      })
      it('dynamic view initialization 2', function () {
        expect(pview.resultdata.length).toEqual(0);
      });
 
 
      // compare how many documents are in results before adding new ones
      var pviewResultsetLenBefore = pview.resultset.filteredrows.length;
 
      users.insert({
        name: 'abc',
        age: 21,
        lang: 'English'
      });
 
      users.insert({
        name: 'def',
        age: 25,
        lang: 'English'
      });
 
      // now see how many are in resultset (without rebuilding persistent view)
      var pviewResultsetLenAfter = pview.resultset.filteredrows.length;
 
      // only one document should have been added to resultset (1 was filtered out)
      it('dv resultset is valid',
        function () {
          expect(pviewResultsetLenBefore + 1).toEqual(pviewResultsetLenAfter);
        });
 
 
      // Test sorting and lazy build of resultdata
 
      // retain copy of internal resultset's filteredrows before lazy sort
      var frcopy = pview.resultset.filteredrows.slice();
      pview.data();
      // now make a copy of internal result's filteredrows after lazy sort
      var frcopy2 = pview.resultset.filteredrows.slice();
 
      // verify filteredrows logically matches resultdata (irrelevant of sort)
      for (var idxFR = 0; idxFR < frcopy2.length; idxFR++) {
        it('dynamic view resultset/resultdata consistency', function () {
          expect(pview.resultdata[idxFR]).toEqual(pview.collection.data[frcopy2[idxFR]]);
        });
      }
      // now verify they are not exactly equal (verify sort moved stuff)
      it('dynamic view sort', function () {
        expect(frcopy).toEqual(frcopy2)
      });
    });
  });
 
  describe('stepDynamicViewPersistence', function () {
    it('works', function duplicateItemFoundOnIndex() {
      var test = db.addCollection('nodupes', ['index']);
 
      var item = test.insert({
        index: 'key',
        a: 1
      });
 
      var results = test.find({
        index: 'key'
      });
      it('one result exists', function () {
        expect(results.length).toEqual(1);
      });
      it('the correct result is returned', function () {
        expect(results[0].a).toEqual(1);
      });
 
 
      item.a = 2;
      test.update(item);
 
      results = test.find({
        index: 'key'
      });
 
      it('one result exists', function () {
        expect(results.length).toEqual(1);
      });
      it('the correct result is returned', function () {
        expect(results[0].a).toEqual(2);
      });
    });
  });
 
  describe('stepDynamicViewPersistence', function () {
    it('works', function testEmptyTableWithIndex() {
      var itc = db.addCollection('test', ['testindex']);
 
      var resultsNoIndex = itc.find({
        'testid': 2
      });
      expect(resultsNoIndex.length).toEqual(0);
 
      var resultsWithIndex = itc.find({
        'testindex': 4
      });
      it('no results found', function () {
        expect(resultsWithIndex.length).toEqual(0);
      });
    });
  });
 
  describe('stepDynamicViewPersistence', function () {
    it('works', function testAnonym() {
      var coll = db.anonym([{
        name: 'joe'
      }, {
        name: 'jack'
      }], ['name']);
      it('Anonym collection', function () {
        expect(coll.data.length).toEqual(2);
      });
      it('Collection not found', function () {
        expect(db.getCollection('anonym')).toEqual(null);
      });
      coll.name = 'anonym';
      db.loadCollection(coll);
      it('Anonym collection loaded', function () {
        expect(!!db.getCollection('anonym') === true).toBeTruthy();
      });
      coll.clear();
      it('No data after coll.clear()', function () {
        expect(0).toEqual(coll.data.length)
      });
    });
  });
 
  describe('stepDynamicViewPersistence', function () {
    it('works', function testCollections() {
      var db = new loki('testCollections');
      db.name = 'testCollections';
      it('DB name', function () {
        expect(db.getName()).toEqual('testCollections');
      });
      var t = db.addCollection('test1', {
        transactional: true
      });
      db.addCollection('test2');
      suite.assertThrows('Throw error on wrong remove', function () {
        t.remove('foo');
      }, Error);
      suite.assertThrows('Throw error on non-synced doc', function () {
        t.remove({
          name: 'joe'
        });
      }, Error);
      it('List collections', function () {
        expect(db.listCollections().length).toEqual(2);
      });
      t.clear();
      var users = [{
        name: 'joe'
      }, {
        name: 'dave'
      }];
      t.insert(users);
 
      it('2 docs after array insert', function () {
        expect(2).toEqual(t.data.length)
      });
      t.remove(users);
      it('0 docs after array remove', function () {
        expect(0).toEqual(t.data.length)
      });
 
      function TestError() {}
      TestError.prototype = new Error;
      db.autosaveEnable();
      db.on('close', function () {
        throw new TestError;
      });
      suite.assertThrows('Throw error on purpose on close', function () {
        db.close(function () {
          return;
        });
      }, TestError);
    });
  });
});