Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Tests to verify the count of colors returned matches the count requested #21

Draft
wants to merge 7 commits into
base: master
Choose a base branch
from
47 changes: 47 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,51 @@ describe('get-image-colors', function () {
done()
})
})

it('returns 5 colors by default', function (done) {
const expectedCount = 5
getColors(path.join(__dirname, '/fixtures/thumb.png'), function (err, palette) {
if (err) throw err
assert(Array.isArray(palette))
assert.equal(palette.length, expectedCount)
palette.forEach(color => {
assert(color.hex().match(/^#[0-9a-f]{3,6}$/i))
})
done()
})
})

it('returns 7 colors when options with count:7 specified', function (done) {
const expectedCount = 7
const options = {
count: expectedCount,
type: 'image/png'
}
getColors(path.join(__dirname, '/fixtures/thumb.png'), options, function (err, palette) {
if (err) throw err
assert(Array.isArray(palette))
assert.equal(palette.length, expectedCount)
palette.forEach(color => {
assert(color.hex().match(/^#[0-9a-f]{3,6}$/i))
})
done()
})
})

it('returns 10 colors when options with count:10 specified', function (done) {
const expectedCount = 10
const options = {
count: expectedCount,
type: 'image/png'
}
getColors(path.join(__dirname, '/fixtures/thumb.png'), options, function (err, palette) {
if (err) throw err
assert(Array.isArray(palette))
assert.equal(palette.length, expectedCount)
palette.forEach(color => {
assert(color.hex().match(/^#[0-9a-f]{3,6}$/i))
})
done()
})
})
})