Skip to content

Commit

Permalink
Throw when mixing StoreWatchMixin in without calling as a function
Browse files Browse the repository at this point in the history
  • Loading branch information
Brandon Tilley committed May 18, 2014
1 parent 44ee073 commit 682817e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
10 changes: 9 additions & 1 deletion lib/store_watch_mixin.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
_ = require("lodash");

module.exports = function() {
var StoreWatchMixin = function() {
var storeNames = Array.prototype.slice.call(arguments);
return {
componentWillMount: function() {
Expand All @@ -26,3 +26,11 @@ module.exports = function() {
}
};
};

StoreWatchMixin.componentWillMount = function() {
throw new Error("Fluxbox.StoreWatchMixin is a function that takes one or more " +
"store names as parameters and returns the mixin, e.g.: " +
"mixins[Fluxbox.StoreWatchMixin(\"Store1\", \"Store2\")]");
};

module.exports = StoreWatchMixin;
10 changes: 10 additions & 0 deletions test/unit/test_store_watch_mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,14 @@ describe("FluxMixin", function() {
done();
});
});

it("throws when attempting to mix in the function directly", function() {
var Comp = React.createClass({
mixins: [Fluxbox.StoreWatchMixin],
render: function() { return React.DOM.div(); }
});
expect(function() {
React.renderComponentToString(Comp());
}).to.throw(/StoreWatchMixin.*function/);
});
});

0 comments on commit 682817e

Please sign in to comment.