Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/image/loading_displaying.js
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,11 @@ function loadingDisplaying(p5, fn){
if (typeof duration !== 'number') {
throw TypeError('Duration parameter must be a number');
}
// a non-positive duration captures zero frames, which later crashes
// in palette generation (frames[0] is undefined). reject early.
if (duration <= 0) {
throw RangeError('Duration parameter must be greater than 0');
}

// extract variables for more comfortable use
const delay = (options && options.delay) || 0; // in seconds
Expand Down
5 changes: 5 additions & 0 deletions test/unit/image/downloading.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,11 @@ suite('Downloading', () => {
assert.typeOf(mockP5Prototype.saveGif, 'function');
});

test('should reject a non-positive duration', async () => {
await expect(mockP5Prototype.saveGif('myGif', 0)).rejects.toThrow();
await expect(mockP5Prototype.saveGif('myGif', -3)).rejects.toThrow();
});

// TODO: this implementation need refactoring
test.todo('should not throw an error', async () => {
await mockP5Prototype.saveGif('myGif', 3);
Expand Down