From 15b0073f7b14679ebd6c43c1cf79bfb9c64b35c2 Mon Sep 17 00:00:00 2001 From: sherwinski Date: Wed, 13 Mar 2019 10:58:23 -0700 Subject: [PATCH] fix: ensure `fit` parameter will respect overriding value, fixes #268 (#311) --- package.json | 3 ++- src/react-imgix-bg.jsx | 2 +- test/integration/react-imgix.test.jsx | 24 ++++++++++++++++++++++++ 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index d1395ac3..92c15a1f 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,8 @@ "author": "Frederick Fogerty (https://github.com/frederickfogerty)", "contributors": [ "Frederick Fogerty (https://github.com/frederickfogerty)", - "Max Kolyanov (https://github.com/maxkolyanov)" + "Max Kolyanov (https://github.com/maxkolyanov)", + "Sherwin Heydarbeygi (https://github.com/sherwinski)" ], "license": "ISC", "bugs": { diff --git a/src/react-imgix-bg.jsx b/src/react-imgix-bg.jsx index c86cfe18..3472c1a8 100644 --- a/src/react-imgix-bg.jsx +++ b/src/react-imgix-bg.jsx @@ -84,11 +84,11 @@ const BackgroundImpl = props => { const renderedSrc = (() => { const srcOptions = { + fit: "crop", ...imgixParams, ...(disableLibraryParam ? {} : { ixlib: `react-${PACKAGE_VERSION}` }), width, height, - fit: "crop", dpr }; diff --git a/test/integration/react-imgix.test.jsx b/test/integration/react-imgix.test.jsx index b63babcf..38d17713 100644 --- a/test/integration/react-imgix.test.jsx +++ b/test/integration/react-imgix.test.jsx @@ -559,6 +559,30 @@ describe("Background Mode", () => { expect(ref instanceof HTMLElement).toBe(true); expect(findURIfromSUT(sut).getQueryParamValue("w")).toBe("100"); }); + it("the fit parameter defaults to 'crop'", async () => { + const sut = await renderBGAndWaitUntilLoaded( +
+ +
Content
+
+
+ ); + + const bgImageSrcURL = findURIfromSUT(sut); + expect(bgImageSrcURL.getQueryParamValue("fit")).toBe("crop"); + }); + it("the fit parameter can be overriden", async () => { + const sut = await renderBGAndWaitUntilLoaded( +
+ +
Content
+
+
+ ); + + const bgImageSrcURL = findURIfromSUT(sut); + expect(bgImageSrcURL.getQueryParamValue("fit")).toBe("clip"); + }); }); function injectScript(src) {