hwillson / meteor-stub-collections

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

Any second stubbed collection does not clean up #24

Closed bvanderdrift closed 6 years ago

bvanderdrift commented 6 years ago

I am writing tests with two collections which are client-side only. When calling restore and stub again after inserting, the first collection that was stubbed will be emptied, while the second will not. Please see this snippet:

let Collection1 = new Mongo.Collection(null);
let Collection2 = new Mongo.Collection(null);

StubCollections.stub([Collection1, Collection2]);

Collection1.insert({a: "a"});
Collection2.insert({b: "b"});

StubCollections.restore();

StubCollections.stub([Collection1, Collection2]);

Collection1.insert({c: "c"});
Collection2.insert({d: "d"});

console.log(Collection1.find().fetch()); //[{c: "c"}]
console.log(Collection2.find().fetch()); //[{b: "b", d: "d"}]

Same happens when using

StubCollections.stub(Collection1);
StubCollections.stub(Collection2);

seperatly