Skip to content

Commit bbc98bd

Browse files
committed
Add test for reactive query with executeBatch
1 parent 459754f commit bbc98bd

File tree

1 file changed

+71
-0
lines changed

1 file changed

+71
-0
lines changed

example/src/tests/reactive.ts

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,77 @@ describe('Reactive queries', () => {
202202
unsubscribe3();
203203
});
204204

205+
it('Row reactive query with executeBatch', async () => {
206+
let firstReactiveRan = false;
207+
let secondReactiveRan = false;
208+
let emittedUser = null;
209+
210+
const unsubscribe = db.reactiveExecute({
211+
query: 'SELECT * FROM User;',
212+
arguments: [],
213+
fireOn: [
214+
{
215+
table: 'User',
216+
ids: [2],
217+
},
218+
],
219+
callback: () => {
220+
firstReactiveRan = true;
221+
},
222+
});
223+
224+
const unsubscribe2 = db.reactiveExecute({
225+
query: 'SELECT * FROM User;',
226+
arguments: [],
227+
fireOn: [
228+
{
229+
table: 'Foo',
230+
},
231+
],
232+
callback: () => {
233+
secondReactiveRan = true;
234+
},
235+
});
236+
237+
const unsubscribe3 = db.reactiveExecute({
238+
query: 'SELECT name FROM User;',
239+
arguments: [],
240+
fireOn: [
241+
{
242+
table: 'User',
243+
ids: [1],
244+
},
245+
],
246+
callback: data => {
247+
emittedUser = data.rows[0];
248+
},
249+
});
250+
251+
await db.executeBatch([
252+
[
253+
'INSERT INTO User (id, name, age, networth, nickname) VALUES (?, ?, ?, ?, ?);',
254+
[1, 'John', 30, 1000, 'Johnny'],
255+
],
256+
]);
257+
258+
await sleep(0);
259+
260+
await db.transaction(async tx => {
261+
await tx.execute('UPDATE User SET name = ? WHERE id = ?;', ['Foo', 1]);
262+
});
263+
264+
await sleep(0);
265+
266+
expect(!!firstReactiveRan).toBe(false);
267+
expect(!!secondReactiveRan).toBe(false);
268+
expect(emittedUser).toDeepEqual({
269+
name: 'Foo',
270+
});
271+
unsubscribe();
272+
unsubscribe2();
273+
unsubscribe3();
274+
});
275+
205276
it('Update hook and reactive queries work at the same time', async () => {
206277
let promiseResolve: any;
207278
let promise = new Promise(resolve => {

0 commit comments

Comments
 (0)