Browse Source

Commit 9-5-2: Added tests to the package.

Frederic G. MARAND 9 years ago
parent
commit
e47daecc09

+ 1 - 0
packages/fgm:errors/README.md

@@ -0,0 +1 @@
+This is the errors package from chapter 9.5 of _Discover Meteor_.

+ 0 - 5
packages/fgm:errors/errors-tests.js

@@ -1,5 +0,0 @@
-// Write your tests here!
-// Here is an example.
-Tinytest.add('example', function (test) {
-  test.equal(true, true);
-});

+ 24 - 0
packages/fgm:errors/errors_tests.js

@@ -0,0 +1,24 @@
+
+Tinytest.add('Errors - collection', function (test) {
+  // Collection is local, hence empty on start.
+  test.equal(Errors.collection.find({}).count(), 0);
+
+  Errors.throw('A new error');
+  test.equal(Errors.collection.find({}).count(), 1);
+
+  Errors.collection.remove({});
+});
+
+Tinytest.addAsync('Errors - template', function (test, done) {
+  Errors.throw('A new error');
+  test.equal(Errors.collection.find({}).count(), 1);
+
+  // Render the template.
+  UI.insert(UI.render(Template.meteorErrors), document.body);
+
+  // Make sure the error collection is emptied after
+  Meteor.setTimeout(function () {
+    test.equal(Errors.collection.find({}).count(), 0);
+    done();
+  }, Errors.delay + 200);
+});

+ 7 - 4
packages/fgm:errors/package.js

@@ -10,7 +10,7 @@ Package.describe({
 
   // By default, Meteor will default to using README.md for documentation.
   // To avoid submitting documentation, set this field to null.
-  // documentation: 'README.md'
+  documentation: 'README.md'
 });
 
 Package.onUse(function(api) {
@@ -26,7 +26,10 @@ Package.onUse(function(api) {
 });
 
 Package.onTest(function(api) {
-  api.use('tinytest');
-  api.use('fgm:errors');
-  api.addFiles('errors-tests.js');
+  var where = 'client';
+
+  api.use('fgm:errors', where);
+  api.use(['tinytest', 'test-helpers'], where);
+
+  api.addFiles('errors_tests.js', where);
 });