package com.contentsquare.rn.erroranalysis import androidx.test.ext.junit.runners.AndroidJUnit4 import com.contentsquare.android.error.analysis.ErrorAnalysis import com.contentsquare.rn.ErrorAnalysisModule import com.facebook.react.bridge.JavaOnlyArray import com.facebook.react.bridge.ReactApplicationContext import io.mockk.* import org.junit.Assert.* import org.junit.Test import org.junit.runner.RunWith import org.robolectric.annotation.Config @RunWith(AndroidJUnit4::class) @Config(manifest = Config.NONE) class ErrorAnalysisModuleTest { // mock private val mockReactApplicationContext = mockk() // object under test private val underTest = ErrorAnalysisModule(mockReactApplicationContext) init { mockkObject(ErrorAnalysis) } @Test fun `calls the SDK's function with the expected patterns array passed`() { // given val mockPattern = listOf("https://contentsquare.com/store/:store_id/:email") val mockPatternsList = JavaOnlyArray.from(mockPattern) // when underTest.setURLMaskingPatterns(mockPatternsList) // then verify { ErrorAnalysis.setUrlMaskingPatterns(mockPattern) } } @Test fun `when calling triggerNativeCrash() it should crash the app in Android code`() { try { underTest.triggerNativeCrash() fail("Expected exception not thrown") } catch (e: RuntimeException) { // Verify that the exception is thrown with the expected message assertEquals("This is purposely triggered native crash", e.message) } } }