, div);
+ setState({m: 0});
+ test.equal(getInnerHtml(div), 'AAA');
+
+ ReactDOM.unmountComponentAtNode(div);
+ });
+
+ function waitFor(func, callback) {
+ Tracker.autorun(function (c) {
+ if (func()) {
+ c.stop();
+ callback();
+ }
+ });
+ };
+
+ testAsyncMulti('withTracker - resubscribe', [
+ function (test, expect) {
+ var self = this;
+ self.div = document.createElement("DIV");
+ self.collection = new Mongo.Collection("withTracker-mixin-coll");
+ self.num = new ReactiveVar(1);
+ self.someOtherVar = new ReactiveVar('foo');
+ self.Foo = withTracker(() => {
+ self.handle =
+ Meteor.subscribe("withTracker-mixin-sub",
+ self.num.get());
+
+ return {
+ v: self.someOtherVar.get(),
+ docs: self.collection.find().fetch()
+ };
+ })((props) => {
+ self.data = props;
+ return {
+ _.map(props.docs, (doc) => {doc._id})
+ }
;
+ });
+
+ self.component = ReactDOM.render(, self.div);
+ test.equal(getInnerHtml(self.div), '');
+
+ var handle = self.handle;
+ test.isFalse(handle.ready());
+
+ waitFor(() => handle.ready(),
+ expect());
+ },
+ function (test, expect) {
+ var self = this;
+ test.isTrue(self.handle.ready());
+ test.equal(getInnerHtml(self.div), 'id1
');
+
+ self.someOtherVar.set('bar');
+ self.oldHandle1 = self.handle;
+
+ // can't call Tracker.flush() here (we are in a Tracker.flush already)
+ Tracker.afterFlush(expect());
+ },
+ function (test, expect) {
+ var self = this;
+ var oldHandle = self.oldHandle1;
+ var newHandle = self.handle;
+ test.notEqual(oldHandle, newHandle); // new handle
+ test.equal(newHandle.subscriptionId, oldHandle.subscriptionId); // same sub
+ test.isTrue(newHandle.ready()); // doesn't become unready
+ // no change to the content
+ test.equal(getInnerHtml(self.div), 'id1
');
+
+ // ok, now change the `num` argument to the subscription
+ self.num.set(2);
+ self.oldHandle2 = newHandle;
+ Tracker.afterFlush(expect());
+ },
+ function (test, expect) {
+ var self = this;
+ // data is still there
+ test.equal(getInnerHtml(self.div), 'id1
');
+ // handle is no longer ready
+ var handle = self.handle;
+ test.isFalse(handle.ready());
+ // different sub ID
+ test.isTrue(self.oldHandle2.subscriptionId);
+ test.isTrue(handle.subscriptionId);
+ test.notEqual(handle.subscriptionId, self.oldHandle2.subscriptionId);
+
+ waitFor(() => handle.ready(),
+ expect());
+ },
+ function (test, expect) {
+ var self = this;
+ // now we see the new data! (and maybe the old data, because
+ // when a subscription goes away, its data doesn't disappear right
+ // away; the server has to tell the client which documents or which
+ // properties to remove, and this is not easy to wait for either; see
+ // https://github.com/meteor/meteor/issues/2440)
+ test.equal(getInnerHtml(self.div).replace('id1', ''),
+ 'id2
');
+
+ self.someOtherVar.set('baz');
+ self.oldHandle3 = self.handle;
+
+ Tracker.afterFlush(expect());
+ },
+ function (test, expect) {
+ var self = this;
+ test.equal(self.data.v, 'baz');
+ test.notEqual(self.oldHandle3, self.handle);
+ test.equal(self.oldHandle3.subscriptionId,
+ self.handle.subscriptionId);
+ test.isTrue(self.handle.ready());
+ },
+ function (test, expect) {
+ ReactDOM.unmountComponentAtNode(this.div);
+ // break out of flush time, so we don't call the test's
+ // onComplete from within Tracker.flush
+ Meteor.defer(expect());
+ }
+ ]);
+
+ // Tinytest.add(
+ // "withTracker - print warning if return cursor from withTracker",
+ // function (test) {
+ // var coll = new Mongo.Collection(null);
+ // var ComponentWithCursor = () => {
+ // withTracker(() => {
+ // return {
+ // theCursor: coll.find()
+ // };
+ // });
+ // return ;
+ // };
+
+ // // Check if we print a warning to console about props
+ // // You can be sure this test is correct because we have an identical one in
+ // // react-runtime-dev
+ // let warning;
+ // try {
+ // var oldWarn = console.warn;
+ // console.warn = function specialWarn(message) {
+ // warning = message;
+ // };
+
+ // var div = document.createElement("DIV");
+ // ReactDOM.render(, div);
+
+ // test.matches(warning, /cursor before returning it/);
+ // } finally {
+ // console.warn = oldWarn;
+ // }
+ // });
+
+} else {
+ Meteor.publish("withTracker-mixin-sub", function (num) {
+ Meteor.defer(() => { // because subs are blocking
+ this.added("withTracker-mixin-coll", 'id'+num, {});
+ this.ready();
+ });
+ });
+}