diff --git a/packages/messaging/jest.config.js b/packages/messaging/jest.config.js index 6d8993ba..08b225d8 100644 --- a/packages/messaging/jest.config.js +++ b/packages/messaging/jest.config.js @@ -1,4 +1,12 @@ module.exports = { preset: "react-native", testMatch: ["/src/ui/**/*.spec.tsx"], -}; + collectCoverage: true, + collectCoverageFrom: [ + "/src/ui/components/**/*.{ts,tsx}", // only components + "!**/*.spec.tsx", + "!**/__tests__/**", + ], + coverageReporters: ["text", "text-summary", "html", "lcov"], + coverageDirectory: "/coverage", +}; \ No newline at end of file diff --git a/packages/messaging/src/ui/components/Button/Button.spec.tsx b/packages/messaging/src/ui/components/Button/Button.spec.tsx index 8639e323..82382ba2 100644 --- a/packages/messaging/src/ui/components/Button/Button.spec.tsx +++ b/packages/messaging/src/ui/components/Button/Button.spec.tsx @@ -9,11 +9,11 @@ ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ +import { fireEvent, render, screen } from '@testing-library/react-native'; import React from 'react'; -import { render, screen, fireEvent } from '@testing-library/react-native'; import { Linking } from 'react-native'; -import Button from './Button'; import { ThemeProvider } from '../../theme/ThemeProvider'; +import Button from './Button'; // Mock Linking.openURL jest.spyOn(Linking, 'openURL'); @@ -157,6 +157,25 @@ describe('Button', () => { expect(Linking.openURL).toHaveBeenCalledWith(testUrl); }); + it('should warn if openURL throws', () => { + const warnSpy = jest.spyOn(console, 'warn').mockImplementation(() => {}); + const testUrl = 'https://example.com'; + (Linking.openURL as unknown as jest.Mock).mockImplementationOnce(() => { + throw new Error('open failed'); + }); + + render(