Skip to content

Commit e4ab700

Browse files
committed
fix: test cases, avoid null on destructure
1 parent deebbf9 commit e4ab700

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

packages/pluggableWidgets/barcode-scanner-web/src/components/BarcodeScanner.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,17 @@ export function BarcodeScanner({
6969
}: BarcodeScannerProps): ReactElement | null {
7070
const [errorMessage, setError] = useCustomErrorMessage();
7171
const canvasMiddleRef = useRef<HTMLDivElement>(null);
72-
const { ref: videoRef, useBrowserAPI } = useReader({
72+
const reader = useReader({
7373
onSuccess: onDetect,
7474
onError: setError,
7575
useCrop: showMask,
7676
barcodeFormats,
7777
useAllFormats,
7878
canvasMiddleRef
7979
});
80+
81+
const { ref: videoRef, useBrowserAPI } = reader ?? {};
82+
8083
const supportsCameraAccess = typeof navigator?.mediaDevices?.getUserMedia === "function";
8184
const onCanPlay = useCallback((event: SyntheticEvent<HTMLVideoElement>) => {
8285
if (event.currentTarget.paused) {

packages/pluggableWidgets/barcode-scanner-web/src/components/__tests__/__snapshots__/BarcodeScanner.spec.tsx.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
exports[`Barcode scanner does not show the overlay when the user opts out of it 1`] = `
44
<DocumentFragment>
55
<div
6-
class="mx-barcode-scanner"
6+
class="mx-barcode-scanner mx-zxing-detector"
77
style="width: 100%; height: 100%;"
88
>
99
<div
@@ -20,7 +20,7 @@ exports[`Barcode scanner does not show the overlay when the user opts out of it
2020
exports[`Barcode scanner renders video and overlay correctly 1`] = `
2121
<DocumentFragment>
2222
<div
23-
class="mx-barcode-scanner"
23+
class="mx-barcode-scanner mx-zxing-detector"
2424
style="width: 100%; height: 100%;"
2525
>
2626
<div

0 commit comments

Comments
 (0)