How to test onBarcodeScanned for Expo Barcode Scanner

Please provide the following:

  1. SDK Version: 47
  2. Platforms(Android/iOS/web/all): All
  3. Add the appropriate “Tag” based on what Expo library you have a question on.

Hello everyone, can any experienced expo developers share with me what is the best practices on how to test the function invoked from onBarCodeScanned in BarCodeScanner component? Appreciate any insights!

Hi @cyberform,

Do you mean to test the function in a project? For that, you can check the callback’s usage in the example from Expo documentation here: BarCodeScanner - Expo Documentation.

Thanks for the prompt reply @amanhimself

Below is an example code. I want to test handleBarCodeScanned function.

There are 2 approaches I thought of -

  1. Blackbox testing
  2. Whitebox testing

For (1), I will need testing-library/react-native, but how do I trigger that particular event if there is no QR code available?

For (2), I can’t find any way to invoke the handleBarCodeScanned function and also how to structure it for whitebox testing more specifically for this example despite searching online.

function QRBarCodeScanner() {

const handleBarCodeScanned = (barcodeParams: BarCodeScannerResult): void => {
return (
    <View style={tailwind('container')}>
        onBarCodeScanned={scanned ? undefined : handleBarCodeScanned}
      {scanned && <Button title={'Tap to Scan Again'} onPress={() => setScanned(false)} />}

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.