Test builder class for easier testing #43
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Since we start cover locales with tests it would be great to have easier tool to test the time, because sometimes it's sad to calculate, e.g. what is the result of
adding 15 days to 18 of December, 2016
. Moreover it would be great to have ability to "read" test written for other languages.This PR introduces a class for easier testing. It wraps the
timeago
and provides human-friendly methods for manipulations with internaltimeago().format
method. Thanks to these interface it becomes intuitively clear about which piece of time you test regardless of the language.How to use
tests/test-builder.js
exports factory method that accepts the same arguments as thetimeago
function and returns an instance of the builder with familiar API.Instance API
register(code, fn, use)
useLocale(code)
getFormat(format)
addSeconds(n)
addMinutes(n)
addHours(n)
addDays(n)
addWeeks(n)
addMonths(n)
addYears(n)
subSeconds(n)
subMinutes(n)
subHours(n)
subDays(n)
subWeeks(n)
subMonths(n)
subYears(n)
add(obj)
sub(obj)
obj: {seconds?: number, minutes?: number, hours?: number, days?: number, weeks?: number, months?: number, years?: number}
Take a look onto attached test file for the
ru
locale, hope you like it.@hustcc why did you change your profile photo? It was cute 😜