Skip to content

Commit c417b06

Browse files
Re-enable database@exp tests (#4731)
1 parent 9fc62d3 commit c417b06

File tree

1 file changed

+58
-4
lines changed

1 file changed

+58
-4
lines changed

packages/database/test/exp/integration.test.ts

Lines changed: 58 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,15 @@ import {
2727
ref,
2828
refFromURL
2929
} from '../../exp/index';
30-
import { set } from '../../src/exp/Reference_impl';
30+
import { onValue, set } from '../../src/exp/Reference_impl';
31+
import { EventAccumulatorFactory } from '../helpers/EventAccumulator';
3132
import { DATABASE_ADDRESS, DATABASE_URL } from '../helpers/util';
3233

3334
export function createTestApp() {
3435
return initializeApp({ databaseURL: DATABASE_URL });
3536
}
3637

37-
// TODO(database-exp): Re-enable these tests
38-
describe.skip('Database Tests', () => {
38+
describe('Database@exp Tests', () => {
3939
let defaultApp;
4040

4141
beforeEach(() => {
@@ -65,7 +65,7 @@ describe.skip('Database Tests', () => {
6565
expect(db.app).to.equal(defaultApp);
6666
});
6767

68-
it('Can set and ge tref', async () => {
68+
it('Can set and get ref', async () => {
6969
const db = getDatabase(defaultApp);
7070
await set(ref(db, 'foo/bar'), 'foobar');
7171
const snap = await get(ref(db, 'foo/bar'));
@@ -77,6 +77,60 @@ describe.skip('Database Tests', () => {
7777
await get(refFromURL(db, `${DATABASE_ADDRESS}/foo/bar`));
7878
});
7979

80+
it('Can get updates', async () => {
81+
const db = getDatabase(defaultApp);
82+
const fooRef = ref(db, 'foo');
83+
84+
const ea = EventAccumulatorFactory.waitsForCount(2);
85+
onValue(fooRef, snap => {
86+
ea.addEvent(snap.val());
87+
});
88+
89+
await set(fooRef, 'a');
90+
await set(fooRef, 'b');
91+
92+
const [snap1, snap2] = await ea.promise;
93+
expect(snap1).to.equal('a');
94+
expect(snap2).to.equal('b');
95+
});
96+
97+
it('Can use onlyOnce', async () => {
98+
const db = getDatabase(defaultApp);
99+
const fooRef = ref(db, 'foo');
100+
101+
const ea = EventAccumulatorFactory.waitsForCount(1);
102+
onValue(
103+
fooRef,
104+
snap => {
105+
ea.addEvent(snap.val());
106+
},
107+
{ onlyOnce: true }
108+
);
109+
110+
await set(fooRef, 'a');
111+
await set(fooRef, 'b');
112+
113+
const [snap1] = await ea.promise;
114+
expect(snap1).to.equal('a');
115+
});
116+
117+
it('Can unsubscribe', async () => {
118+
const db = getDatabase(defaultApp);
119+
const fooRef = ref(db, 'foo');
120+
121+
const ea = EventAccumulatorFactory.waitsForCount(1);
122+
const unsubscribe = onValue(fooRef, snap => {
123+
ea.addEvent(snap.val());
124+
});
125+
126+
await set(fooRef, 'a');
127+
unsubscribe();
128+
await set(fooRef, 'b');
129+
130+
const [snap1] = await ea.promise;
131+
expect(snap1).to.equal('a');
132+
});
133+
80134
it('Can goOffline/goOnline', async () => {
81135
const db = getDatabase(defaultApp);
82136
goOffline(db);

0 commit comments

Comments
 (0)