@@ -27,15 +27,15 @@ import {
27
27
ref ,
28
28
refFromURL
29
29
} 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' ;
31
32
import { DATABASE_ADDRESS , DATABASE_URL } from '../helpers/util' ;
32
33
33
34
export function createTestApp ( ) {
34
35
return initializeApp ( { databaseURL : DATABASE_URL } ) ;
35
36
}
36
37
37
- // TODO(database-exp): Re-enable these tests
38
- describe . skip ( 'Database Tests' , ( ) => {
38
+ describe ( 'Database@exp Tests' , ( ) => {
39
39
let defaultApp ;
40
40
41
41
beforeEach ( ( ) => {
@@ -65,7 +65,7 @@ describe.skip('Database Tests', () => {
65
65
expect ( db . app ) . to . equal ( defaultApp ) ;
66
66
} ) ;
67
67
68
- it ( 'Can set and ge tref ' , async ( ) => {
68
+ it ( 'Can set and get ref ' , async ( ) => {
69
69
const db = getDatabase ( defaultApp ) ;
70
70
await set ( ref ( db , 'foo/bar' ) , 'foobar' ) ;
71
71
const snap = await get ( ref ( db , 'foo/bar' ) ) ;
@@ -77,6 +77,60 @@ describe.skip('Database Tests', () => {
77
77
await get ( refFromURL ( db , `${ DATABASE_ADDRESS } /foo/bar` ) ) ;
78
78
} ) ;
79
79
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
+
80
134
it ( 'Can goOffline/goOnline' , async ( ) => {
81
135
const db = getDatabase ( defaultApp ) ;
82
136
goOffline ( db ) ;
0 commit comments