Skip to content

Commit fbccdae

Browse files
committed
Added percent filter tests
1 parent b02cd9b commit fbccdae

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

test/filters.spec.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,29 @@ describe('Filters', function() {
263263
expect(filter(2000)).toBe('2.0 kb')
264264
})
265265

266+
it('percent', function() {
267+
var filter = otherFilters.percent
268+
269+
expect(filter(12)).toBe('12%')
270+
expect(filter(100, 0)).toBe('100%')
271+
expect(filter(100, 1)).toBe('100.0%')
272+
expect(filter(0.974878234, 3)).toBe('97.488%')
273+
expect(filter(0.0003, 1)).toBe('0.0%')
274+
275+
// edge cases
276+
expect(filter(undefined)).toBe('0%')
277+
expect(filter(null)).toBe('0%')
278+
expect(filter("a random string")).toBe('0%')
279+
})
280+
281+
it('percent with global options', function() {
282+
var filter = otherFilters.percent.bind({
283+
percent: { decimalDigits: 1 }
284+
})
285+
286+
expect(filter(100)).toBe('100.0%')
287+
})
288+
266289
it('limitByArray', function () {
267290
var filter = arrayFilters.limitBy
268291
var arr = [1, 2, 3]

0 commit comments

Comments
 (0)