Having some trouble with basic testing

I moved everything into a package like structure. My first package is pretty straight forward:

Players = new Mongo.Collection('players');
Players.attachSchema(new SimpleSchema({
  name: {
    type: String
  score: {
    type: Number,
    max: 100,
    defaultValue: 0

So then my package looks a little like this.

Package.onUse(function (api) {
  api.use(['mongo', 'aldeed:simple-schema', 'aldeed:collection2']);
Package.onTest(function (api) {
  api.use(['ecmascript', 'tinytest', 'players']);

However, it keeps saying that [object Object] has no method attachSchema. This seems a bit weird, because it works fine in my main application, just not in tests. Anyone know what the source of this problem is?

You are telling meteor that 'aldeed:simple-schema', 'aldeed:collection2' should be used “onUse” in the application, when you are running the package normally. However, you are not using those packages onTest, so the test doesn’t have access to those packages and becomes confused.

You therefore need to add 'aldeed:simple-schema', 'aldeed:collection2' to your api.use below Package.onTest

Ah okay, that seems a bit strange, because if you include players, and players includes aldeed:simple-schema, it feels like it is implicitly included in the onTest

Ah, your package is named “players” right? Then it makes some sense. Now that I look at it, I think I was wrong earlier. The package should know to use the aldeed packages itself.

I’d guess you are trying to use attachSchema in your tests? If so then you either need to include the proper use package (aldeed:foo) in the onTest section or use “imply” instead of “use” in the onUse section.

Imply lets users of the package also access the specified dependencies.

See here for more details: