Having some trouble with basic testing


#1

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.versionsFrom('1.2.1');
  api.use(['mongo', 'aldeed:simple-schema', 'aldeed:collection2']);
  api.export('Players');
});
Package.onTest(function (api) {
  api.use(['ecmascript', 'tinytest', 'players']);
  api.addFiles('tests.js')
})

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?


#2

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


#3

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


#5

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.


#6

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:
http://docs.meteor.com/#packagejs