Skip to content

Commit

Permalink
Merge e664b61 into f52cecd
Browse files Browse the repository at this point in the history
  • Loading branch information
JRichlen committed Mar 30, 2018
2 parents f52cecd + e664b61 commit 2f85222
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 0 deletions.
9 changes: 9 additions & 0 deletions chance.js
Expand Up @@ -1373,6 +1373,15 @@
}
};

Chance.prototype.image = function (options) {
options = initOptions(options, { width: 500, height: 500, greyscale: false, blurred: false });

var greyscale = options.greyscale ? 'g/' : '';
var query = options.blurred ? '/?blur' : '/?random';

return 'https://picsum.photos/' + greyscale + options.width + '/' + options.height + query;
}

// -- End Web --

// -- Location --
Expand Down
55 changes: 55 additions & 0 deletions test/test.web.js
Expand Up @@ -540,3 +540,58 @@ test('url() can take and respect extensions', t => {
t.not(url.indexOf('.html'), -1)
})
})

// chance.image()
test('image() returns image url with default width and height', t => {
_.times(1000, () => {
let image = chance.image()
t.true(_.isString(image))
t.true(image.split('.').length > 1)
t.true(image.split('://').length > 1)
t.true(image.split('picsum.photos').length > 1)
t.true(image.split('/500/500').length > 1)
t.true(image.split('/?random').length > 1)
})
})
test('image() returns image url that respects width and height', t => {
_.times(1000, () => {
let width = chance.natural();
let height = chance.natural();
let image = chance.image({
width,
height
})
t.true(_.isString(image))
t.true(image.split('.').length > 1)
t.true(image.split('://').length > 1)
t.true(image.split('picsum.photos').length > 1)
t.true(image.split('/' + width + '/' + height).length > 1)
t.true(image.split('/?random').length > 1)
})
})
test('image() returns image url that respects greyscale', t => {
_.times(1000, () => {
let image = chance.image({
greyscale: true
})
t.true(_.isString(image))
t.true(image.split('.').length > 1)
t.true(image.split('://').length > 1)
t.true(image.split('picsum.photos').length > 1)
t.true(image.split('/g/500/500').length > 1)
t.true(image.split('/?random').length > 1)
})
})
test('image() returns image url that respects blurred', t => {
_.times(1000, () => {
let image = chance.image({
blurred: true
})
t.true(_.isString(image))
t.true(image.split('.').length > 1)
t.true(image.split('://').length > 1)
t.true(image.split('picsum.photos').length > 1)
t.true(image.split('/500/500').length > 1)
t.true(image.split('/?blur').length > 1)
})
})

0 comments on commit 2f85222

Please sign in to comment.