Skip to content
Permalink
Browse files

Added tests to the package.

sidebar9-5-2
  • Loading branch information
tmeasday committed Oct 20, 2015
1 parent 7ee9b22 commit 6181c4b4e313f7bf52a4686b8c2a95924e8d26b6
Showing with 28 additions and 0 deletions.
  1. +21 −0 packages/tmeasday:errors/errors_tests.js
  2. +7 −0 packages/tmeasday:errors/package.js
@@ -0,0 +1,21 @@
Tinytest.add("Errors - collection", function(test) {
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);

Meteor.setTimeout(function() {
test.equal(Errors.collection.find({}).count(), 0);
done();
}, 3500);
});
@@ -13,4 +13,11 @@ Package.onUse(function (api, where) {

if (api.export)
api.export('Errors');
});

Package.onTest(function(api) {
api.use('tmeasday:errors', 'client');
api.use(['tinytest', 'test-helpers'], 'client');

api.addFiles('errors_tests.js', 'client');
});

10 comments on commit 6181c4b

@robneville73

This comment has been minimized.

Copy link

@robneville73 robneville73 replied Oct 24, 2015

This code does not match the instructions in the book. Specifically the UI.insert line is different from the book. Please update it.

@joshpitzalis

This comment has been minimized.

Copy link

@joshpitzalis joshpitzalis replied Oct 30, 2015

+1

@qingchen1990sc

This comment has been minimized.

Copy link

@qingchen1990sc qingchen1990sc replied Nov 19, 2015

需要在package.onTest 中增 api.addFiles('errors-tests.js', 'client');

@thespacecowboys45

This comment has been minimized.

Copy link

@thespacecowboys45 thespacecowboys45 replied Dec 17, 2015

I get an error (see attached) with this code:

"exception - message UI is not defined"

?
screen shot 2015-12-16 at 9 46 15 pm

@mikebobadilla

This comment has been minimized.

Copy link

@mikebobadilla mikebobadilla replied Jan 1, 2016

yea I was using Template and it says Template not defined.

@MGDSoft

This comment has been minimized.

Copy link

@MGDSoft MGDSoft replied Jan 2, 2016

To fix it api.use(['tinytest', 'test-helpers', 'ui', 'templating'], 'client');

@JeremyIglehart

This comment has been minimized.

Copy link

@JeremyIglehart JeremyIglehart replied Apr 20, 2016

So, I was really having to hunt and peck to find this - Exactly where to add this new support for "ui"

Here are the two files I have:

[microscope dir]/packages/errors/package.js:

Package.describe({
  name: "autoschematic:errors",
  summary: "A pattern to display application errors to the user",
  version: "1.0.0"
});

Package.onUse(function (api, where) {
  api.versionsFrom('0.9.0');

  api.use(['minimongo', 'mongo-livedata', 'templating'], 'client');

  api.addFiles(['errors.js', 'errors_list.html', 'errors_list.js'], 'client');

  if (api.export) 
    api.export('Errors');
});

Package.onTest(function(api) {
  api.use('autoschematic:errors', 'client');
  api.use(['tinytest', 'ui', 'test-helpers', 'templating'], 'client'); 

  api.addFiles('errors_tests.js', 'client');
});

The trick is there in the Package.onTest function you're putting:
api.use(['tinytest', 'ui', 'test-helpers', 'templating'], 'client');

And then your [microscope dir]/packages/errors/errors_tests.js: file will look like this:

Tinytest.add("Errors - collection", function(test) {
  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);

  Meteor.setTimeout(function() {
    test.equal(Errors.collection.find({}).count(), 0);
    done();
  }, 3500);
});

Notice that as people are saying the line
UI.insert(UI.render(Template.meteorErrors), document.body);
is different than in the book where it has this line as
Template.insert(Template.render(Template.meteorErrors), document.body);

I thought that an extended full explanation was in order for this problem.

Thank you to everyone else who helped me get here: @MGDSoft @mbeauchamp7 @GabrielGM And this Issue: Issue #468

Adding this I was able to render:
screen shot 2016-04-20 at 12 12 16 pm

@fossilblue

This comment has been minimized.

Copy link

@fossilblue fossilblue replied Apr 27, 2016

Thanks Jeremy. This solve my issue during testing

@WPBLRUN

This comment has been minimized.

Copy link

@WPBLRUN WPBLRUN replied Aug 27, 2016

Thanks Jeremy.That's useful!!

@Edditoria

This comment has been minimized.

Copy link

@Edditoria Edditoria replied Sep 29, 2016

Thanks @JeremyIglehart for explanation.

Please sign in to comment.
You can’t perform that action at this time.