Skip to content

Commit e0787b7

Browse files
committed
Add more tests
1 parent 684725a commit e0787b7

File tree

1 file changed

+34
-1
lines changed

1 file changed

+34
-1
lines changed

test/client/doc.js

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
var Backend = require('../../lib/backend');
22
var expect = require('expect.js');
33

4-
describe('client query subscribe', function() {
4+
describe('client doc', function() {
55

66
beforeEach(function() {
77
this.backend = new Backend();
@@ -25,6 +25,39 @@ describe('client query subscribe', function() {
2525
expect(doc).not.equal(doc2);
2626
});
2727

28+
it('calling doc.destroy on subscribed doc unregisters it (no callback)', function() {
29+
var connection = this.connection;
30+
var doc = connection.get('dogs', 'fido');
31+
expect(connection.getExisting('dogs', 'fido')).equal(doc);
32+
33+
doc.subscribe(function(err) {
34+
if (err) return done(err);
35+
doc.destroy();
36+
doc.whenNothingPending(function() {
37+
expect(connection.getExisting('dogs', 'fido')).equal(undefined);
38+
39+
var doc2 = connection.get('dogs', 'fido');
40+
expect(doc).not.equal(doc2);
41+
});
42+
});
43+
});
44+
45+
it('calling doc.destroy on subscribed doc unregisters it (with callback)', function() {
46+
var connection = this.connection;
47+
var doc = connection.get('dogs', 'fido');
48+
expect(connection.getExisting('dogs', 'fido')).equal(doc);
49+
50+
doc.subscribe(function(err) {
51+
if (err) return done(err);
52+
doc.destroy(function() {
53+
expect(connection.getExisting('dogs', 'fido')).equal(undefined);
54+
55+
var doc2 = connection.get('dogs', 'fido');
56+
expect(doc).not.equal(doc2);
57+
});
58+
});
59+
});
60+
2861
it('getting then destroying then getting returns a new doc object', function() {
2962
var doc = this.connection.get('dogs', 'fido');
3063
doc.destroy();

0 commit comments

Comments
 (0)