hwillson / meteor-stub-collections

Stub out Meteor collections with in-memory local collections.
MIT License
24 stars 17 forks source link

Simple Schema Returning null #8

Closed drewmoore closed 7 years ago

drewmoore commented 7 years ago

Hi, this covers a usage case when using either the aldeed:collection2 or aldeed:simple-schema package. Although this doesn't usually affect functionality, when there is client-side code referencing a property on the schema, the schema is null, and therefore there is an error.

For example, for a given collection Dogs: Dogs.simpleSchema()._schema would throw TypeError: Cannot read property '_schema' of null. This doesn't happen outside of running tests. Would it be possible to include the schema in the collection stub? If I'm doing something wrong, please let me know. Thanks!

hwillson commented 7 years ago

Great catch - makes sense to me. Thanks for the PR!

hwillson commented 7 years ago

v1.0.2 has been published with your changes - thanks again!

eric-burel commented 7 years ago

Hi, I have a short question about the interactions between stub-collections and collection2. Here is a piece of test I created :

  it("Should create a clean UserState object on signup", function(){
      const userId = Meteor.call('user.signup', dummyUser.email, dummyUser.password)
      const userState = UserState.findOne({userId})

      assert.deepEqual(userState, UserState.schema.clean({userId}))
    })

UserState has been stubbed, and the idea of the test is that the userState object in the stub collection should have been created and cleaned. However it is not, and userState equals {userId:"foobar"} where it should equal something similar to {userId:"foobar", someAutoGeneratedValue: {...} }. It seems that collection2 is not applied on the stubbed collection.

Is that an expected behaviour ? Since stub-collections is meant for unit test, I could understand that it does not apply collection2, but I am not sure. It seems to be related to this issue, but I don't clearly understand all implications here.

Thanks !

Edit : even if the test does not pass, my code works fine, the clean function is correctly triggered on insert