Tinytest didn't run addAsync() test

One more Tinytest question…

I ran the following Tinytest code from the Discover Meteor book, along with the following package.js code, and when the tests ran, they passed, but, there was one problem:

The add() test function ran, but the addAsync() function that was supposed to test the Template functionality of the Errors package didn’t run. I checked & double-checked that I didn’t accidentally omit or change anything from the book, but I haven’t been able to figure out why the second test suite didn’t run.

Can anyone see what’s causing the addAsync() set of tests not to run?

Thanks.

errors_test.js

Tinytest.add('Errors --> Collection', function (test) {
  test.equal(Errors.collection.find({}).count(), 0);
  Errors.throw('A test 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);
});

package.js

Package.describe({
  name: 'thebionicman:errors',
  version: '1.0.0',
  summary: 'A pattern for displaying application errors to users',
});

Package.onUse(function(api) {
  api.versionsFrom('1.1.0.3');
  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('thebionicman:errors', 'client');
  api.use(['tinytest', 'test-helpers'], 'client');
  api.addFiles('errors_tests.js', 'client');
});

Can you format the posted code properly. It’s like asking for help while spitting in the face. :smile:
You may should consider using sanjo:jasmine. I think it is easier to use.

I know, I’m sorry about that. I fought with the editor but despite multiple tries, I couldn’t get the formatting to work any better - it only applies the background to each individual line, rather than to the entire block of code, and it wouldn’t preserve the code’s indentation levels.

Is there some trick to preserving proper formatting? I didn’t see an indent button in the editor’s UI, and pressing tab just switched the focus to another element.

@Sanjo

Ok, I figured out how to fix the code’s formatting. Sorry about that - it was late when I posted it and I had trouble getting the indentation and spacing preserved.

You wrote TinyTest instead of Tinytest. The capital T typo is the mistake.

To find such errors, just open the Chrome web tools in the browser window where you see the test results. It should show the error in the console there.

Oh man! I hate those sorts of errors - easy to make; hard to find (unless, like you said, you use the browser’s dev tools).

Thanks

The number of times that I typed Meteor.error instead of Meteor.Error and then put a breakpoint on the server, stepped through the code, confirmed all inputs/calls right up to that line, and then do it again…
Or mistyping your own variables…

Believe me, this does not get any better with experience, you just find out how to debug faster! (This is why larger teams are moving to typescript, you get C# level static type check, saves %% time imo) Using Resharper, I just get used to fixing all red underlines before compiling.

Ohhhh, you think that’s embarrassing? I came this close to emailing the authors of the Discover Meteor book to tell them that maybe they should check to make sure they didn’t have a bug in that test code. Then I decided to check it one more time…(thank God). It wasn’t until later that I saw @Sanjo’s helpful response. So… be careful before you try to out-embarrass me. :wink:

I know, type checking helps. But I’ve been writing old-school C code on microcontrollers for some IoT projects. The type-checking does catch a lot of bugs, and it would have caught that one, but there are still ways to make all kinds of baldness-inducing bugs.

1 Like