Implement comparison methods#14
Conversation
All the functionality is in compare, so there is no point in testing is 4 times, we simply only need to check that it was called.
test.js
Outdated
| it('should call compare', function () { | ||
| bd.compareHeight('mobile'); | ||
| bd.compareWidth('mobile'); | ||
| assume(spy.callCount).equals(2); |
There was a problem hiding this comment.
might want to assert the functions are called with the right property e.g. width and height
breakdancer.js
Outdated
|
|
||
| /** | ||
| * Compare current and specified properties of given breakpoint | ||
| * Requires that this.height() and this.width() are implemented |
There was a problem hiding this comment.
wonder if we should safeguard against this, although both native and regular have default implementations.
There was a problem hiding this comment.
I was thinking that because this is already a @private method, we can safeguard this by relying on the fact this.height() and this.width() methods already exist in index.js and index.native.js.
However, it would be worthwhile to throw a ReferenceError if the associated this[property] function does not exist.
breakdancer.js
Outdated
| * @param {String} property height or width | ||
| * @throws {TypeError} If not given breakpoint and property do not exist within the given spec | ||
| * @returns {Number} different between current and specified properties | ||
| * @private |
There was a problem hiding this comment.
In all honestly, I would say you might as well just ditch compareHeight and compareWidth and make the compare method public and keep that as only API.
This PR implements the
compareHeightand thecompareWidthmethods. Here is the documentation added to the README that describes the usage of these methods:compareWidth(breakpoint)Returns the difference between the current width and the given breakpoint. This can be used to check if the window is "greater" than a breakpoint. If the given breakpoint does not have a width, this will always return the current width. If the given breakpoint does not exist, than we return an error.
compareHeight(breakpoint)Same usage as
compareWidthTL;DR
Now you can check if you're "past" a certain breakpoint with
compareWidth('mobile')