Skip to content
This repository was archived by the owner on May 12, 2019. It is now read-only.

Commit c2ff712

Browse files
author
Shawn Lim
committed
write proper test
1 parent d50fc74 commit c2ff712

File tree

3 files changed

+24
-20
lines changed

3 files changed

+24
-20
lines changed

package.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ Package.on_use(function(api, where){
1313
// todo test
1414
Package.on_test(function(api) {
1515
api.use('subscriber', ['client', 'server']);
16-
api.use(['tinytest', 'test-helpers'], 'client');
16+
api.use(['tinytest', 'test-helpers']);
1717

18-
api.add_files('test.js', ['client']);
19-
api.add_files('test-server.js', ['server']);
18+
api.add_files('test.js', ['client', 'server']);
2019
});

test-server.js

Lines changed: 0 additions & 5 deletions
This file was deleted.

test.js

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,25 @@
1-
Tinytest.add("Subscribers collection exist", function(test){
2-
test.equal(Subscribers.find().count(), 0);
3-
});
1+
if(Meteor.isServer){
2+
Subscribers.allow({
3+
remove: function(){
4+
return true
5+
}
6+
})
7+
}
48

5-
Tinytest.add("insertSubscriber method works", function(test){
6-
var count = Subscribers.find().count();
7-
var email = '[email protected]';
8-
Meteor.call('insertSubscriber', email, function(err, id){
9-
// remove the inserted subscriber after a while
10-
Meteor.setTimeout(function(){Subscribers.remove(id)}, 1000);
9+
if(Meteor.isClient){
10+
11+
Tinytest.add("Meteor-Subscriber - subscriber collection exist", function(test){
12+
test.instanceOf(Subscribers, Meteor.Collection)
1113
});
12-
var newCount = Subscribers.find().count();
13-
test.equal(newCount, count+1);
14-
});
1514

15+
testAsyncMulti("Meteor-Subscriber - insertSubscriber method works", [
16+
function(test, expect){
17+
var email = '[email protected]';
18+
Meteor.call('insertSubscriber', email, expect(function(err, id){
19+
test.isFalse(err) // falsy value includes undefined
20+
test.isTrue(id) // truthy value includes a real string
21+
Subscribers.remove(id); // remove the inserted email after testing
22+
}));
23+
}
24+
]);
25+
}

0 commit comments

Comments
 (0)