Closed drewmoore closed 7 years ago
Great catch - makes sense to me. Thanks for the PR!
v1.0.2 has been published with your changes - thanks again!
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
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 throwTypeError: 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!