Skip to content

Commit

Permalink
test: add tests for resettable format
Browse files Browse the repository at this point in the history
  • Loading branch information
rexxars committed Oct 31, 2024
1 parent 69ea8f8 commit 0feb635
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ export class ImageUrlBuilder {
}

// Specify the image format of the image. 'jpg', 'pjpg', 'png', 'webp'
format(format?: ImageFormat) {
format(format?: ImageFormat | undefined) {
return this.withOptions({format})
}

Expand Down
4 changes: 4 additions & 0 deletions test/__snapshots__/builder.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ exports[`builder automatic format 1`] = `"auto=format"`;

exports[`builder can be told to ignore hotspot 1`] = `"https://cdn.sanity.io/images/zp7mbokg/production/Tb9Ew8CXIwaY6R1kjMvI0uRR-2000x3000.jpg?w=100&h=80"`;

exports[`builder can reset format 1`] = `""`;

exports[`builder can set format 1`] = `"fm=jpg"`;

exports[`builder can specify options with url params 1`] = `"https://cdn.sanity.io/images/zp7mbokg/production/Tb9Ew8CXIwaY6R1kjMvI0uRR-2000x3000.jpg?rect=200,300,1600,1200&w=320&h=240"`;

exports[`builder constrains aspect ratio 1`] = `"https://cdn.sanity.io/images/zp7mbokg/production/Tb9Ew8CXIwaY6R1kjMvI0uRR-2000x3000.jpg?rect=200,300,1600,1280&w=100&h=80"`;
Expand Down
10 changes: 10 additions & 0 deletions test/builder.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,16 @@ const cases = [
url: stripPath(urlFor.image(noHotspotImage()).dpr(1).url()),
},

{
name: 'can set format',
url: stripPath(urlFor.image(noHotspotImage()).format('jpg').url()),
},

{
name: 'can reset format',
url: stripPath(urlFor.image(noHotspotImage()).format('jpg').format(undefined).url()),
},

{
name: 'vanity name',
url: urlFor.image(noHotspotImage()).vanityName('moo').url(),
Expand Down

0 comments on commit 0feb635

Please sign in to comment.