From 0feb63518059092507ed1d6c48148e1864054e16 Mon Sep 17 00:00:00 2001 From: Espen Hovlandsdal Date: Wed, 30 Oct 2024 20:16:39 -0700 Subject: [PATCH] test: add tests for resettable format --- src/builder.ts | 2 +- test/__snapshots__/builder.test.ts.snap | 4 ++++ test/builder.test.ts | 10 ++++++++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/builder.ts b/src/builder.ts index a08ee31..d337c7a 100644 --- a/src/builder.ts +++ b/src/builder.ts @@ -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}) } diff --git a/test/__snapshots__/builder.test.ts.snap b/test/__snapshots__/builder.test.ts.snap index fdeccca..8d5abc9 100644 --- a/test/__snapshots__/builder.test.ts.snap +++ b/test/__snapshots__/builder.test.ts.snap @@ -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"`; diff --git a/test/builder.test.ts b/test/builder.test.ts index b3afd3e..3fa4e59 100644 --- a/test/builder.test.ts +++ b/test/builder.test.ts @@ -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(),