Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

Commit

Permalink
refactor(test): change indexedDB.spec to typescript (#660)
Browse files Browse the repository at this point in the history
  • Loading branch information
JiaLiPassion authored and mhevery committed Mar 7, 2017
1 parent 84459f1 commit ea183e9
Show file tree
Hide file tree
Showing 3 changed files with 140 additions and 123 deletions.
3 changes: 2 additions & 1 deletion test/browser_entry_point.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ import './browser/requestAnimationFrame.spec';
import './browser/WebSocket.spec';
import './browser/XMLHttpRequest.spec';
import './browser/MediaQuery.spec';
import './mocha-patch.spec';
import './mocha-patch.spec';
import './patch/indexedDB.spec';
122 changes: 0 additions & 122 deletions test/patch/IndexedDB.spec.js

This file was deleted.

138 changes: 138 additions & 0 deletions test/patch/IndexedDB.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
/**
* @license
* Copyright Google Inc. All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/

'use strict';
import {ifEnvSupports} from '../test-util';

describe(
'IndexedDB', ifEnvSupports('IDBDatabase', function() {
const testZone = Zone.current.fork({name: 'testZone'});
let db;

beforeEach(function(done) {
const openRequest = indexedDB.open('_zone_testdb');
openRequest.onupgradeneeded = function(event) {
db = event.target['result'];
const objectStore = db.createObjectStore('test-object-store', {keyPath: 'key'});
objectStore.createIndex('key', 'key', {unique: true});
objectStore.createIndex('data', 'data', {unique: false});

objectStore.transaction.oncomplete = function() {
const testStore =
db.transaction('test-object-store', 'readwrite').objectStore('test-object-store');
testStore.add({key: 1, data: 'Test data'});
testStore.transaction.oncomplete = function() {
done();
};
};
};
});

afterEach(function(done) {
db.close();

const openRequest = indexedDB.deleteDatabase('_zone_testdb');
openRequest.onsuccess = function(event) {
done();
};
});

describe('IDBRequest', function() {
it('should bind EventTarget.addEventListener', function(done) {
testZone.run(function() {
db.transaction('test-object-store')
.objectStore('test-object-store')
.get(1)
.addEventListener('success', function(event) {
expect(Zone.current.name).toEqual('testZone');
expect(event.target.result.data).toBe('Test data');
done();
});
});
});

it('should bind onEventType listeners', function(done) {
testZone.run(function() {
db.transaction('test-object-store').objectStore('test-object-store').get(1).onsuccess =
function(event) {
expect(Zone.current.name).toEqual('testZone');
expect(event.target.result.data).toBe('Test data');
done();
};
});
});
});

describe('IDBCursor', function() {
it('should bind EventTarget.addEventListener', function(done) {
testZone.run(function() {
db.transaction('test-object-store')
.objectStore('test-object-store')
.openCursor()
.addEventListener('success', function(event) {
const cursor = event.target.result;
if (cursor) {
expect(Zone.current.name).toEqual('testZone');
expect(cursor.value.data).toBe('Test data');
done();
} else {
fail('Error while reading cursor!');
}
});
});
});

it('should bind onEventType listeners', function(done) {
testZone.run(function() {
db.transaction('test-object-store')
.objectStore('test-object-store')
.openCursor()
.onsuccess = function(event) {
const cursor = event.target.result;
if (cursor) {
expect(Zone.current.name).toEqual('testZone');
expect(cursor.value.data).toBe('Test data');
done();
} else {
fail('Error while reading cursor!');
}
};
});
});
});

describe('IDBIndex', function() {
it('should bind EventTarget.addEventListener', function(done) {
testZone.run(function() {
db.transaction('test-object-store')
.objectStore('test-object-store')
.index('data')
.get('Test data')
.addEventListener('success', function(event) {
expect(Zone.current.name).toEqual('testZone');
expect(event.target.result.key).toBe(1);
done();
});
});
});

it('should bind onEventType listeners', function(done) {
testZone.run(function() {
db.transaction('test-object-store')
.objectStore('test-object-store')
.index('data')
.get('Test data')
.onsuccess = function(event) {
expect(Zone.current.name).toEqual('testZone');
expect(event.target.result.key).toBe(1);
done();
};
});
});
});
}));

0 comments on commit ea183e9

Please sign in to comment.