diff --git a/src/components/MaskedTextInput.test.tsx b/src/components/MaskedTextInput.test.tsx
index e0f7ff6..1cd1fe5 100644
--- a/src/components/MaskedTextInput.test.tsx
+++ b/src/components/MaskedTextInput.test.tsx
@@ -1,29 +1,34 @@
import React from 'react'
-import { render, fireEvent, waitFor } from '@testing-library/react-native';
-import { MaskedTextInput } from './MaskedTextInput';
-import { Button, Keyboard, InputAccessoryView } from 'react-native';
-
+import { render, fireEvent, waitFor } from '@testing-library/react-native'
+import { MaskedTextInput } from './MaskedTextInput'
+import { Button, Keyboard, InputAccessoryView } from 'react-native'
describe('', () => {
- const mockedOnChangeText = jest.fn();
+ const mockedOnChangeText = jest.fn()
test('should render correctly without a mask', () => {
const container = render(
- ,
- );
- expect(container).toMatchSnapshot();
+
+ )
+ expect(container).toMatchSnapshot()
})
test('should preserve spaces in rawText when no mask is provided', async () => {
- const onChangeTextMock = jest.fn();
+ const onChangeTextMock = jest.fn()
const container = render(
- );
+ )
- fireEvent.changeText(container.getByTestId('masked-text-input'), 'test test')
+ fireEvent.changeText(
+ container.getByTestId('masked-text-input'),
+ 'test test'
+ )
await waitFor(() => {
expect(onChangeTextMock).toHaveBeenCalledWith('test test', 'test test')
@@ -31,14 +36,14 @@ describe('', () => {
})
test('should remove spaces in rawText when mask is provided', async () => {
- const onChangeTextMock = jest.fn();
+ const onChangeTextMock = jest.fn()
const container = render(
- );
+ )
fireEvent.changeText(container.getByTestId('masked-text-input'), 'ABC 123')
@@ -49,10 +54,10 @@ describe('', () => {
test('should renders correctly with custom mask', () => {
const container = render(
- ,
- );
- expect(container).toMatchSnapshot();
- });
+
+ )
+ expect(container).toMatchSnapshot()
+ })
test('should renders correctly with custom mask default value', () => {
const container = render(
@@ -61,9 +66,9 @@ describe('', () => {
onChangeText={mockedOnChangeText}
defaultValue="ABC-123"
/>
- );
+ )
expect(container.getByDisplayValue('ABC-123')).toBeTruthy()
- });
+ })
test('should renders correctly with currency mask', () => {
const container = render(
@@ -77,9 +82,9 @@ describe('', () => {
}}
onChangeText={mockedOnChangeText}
/>
- );
- expect(container).toMatchSnapshot();
- });
+ )
+ expect(container).toMatchSnapshot()
+ })
test('should mask input text with custom mask', async () => {
const container = render(
@@ -88,14 +93,18 @@ describe('', () => {
onChangeText={mockedOnChangeText}
testID="masked-text-input"
/>
- );
+ )
fireEvent.changeText(container.getByTestId('masked-text-input'), 'RCT777')
await waitFor(() => {
expect(container.getByDisplayValue('RCT-777')).toBeTruthy()
})
- });
+
+ await waitFor(() => {
+ expect(mockedOnChangeText).toHaveBeenCalledWith('RCT-777', 'RCT777')
+ })
+ })
test('should mask input text with currency mask', async () => {
const container = render(
@@ -110,71 +119,87 @@ describe('', () => {
onChangeText={mockedOnChangeText}
testID="masked-text-input"
/>
- );
+ )
fireEvent.changeText(container.getByTestId('masked-text-input'), '5999')
await waitFor(() => {
expect(container.getByDisplayValue('$59.99')).toBeTruthy()
})
- });
+
+ await waitFor(() => {
+ expect(mockedOnChangeText).toHaveBeenCalledWith('$59.99', '5999')
+ })
+ })
+
+ test('should not call onChangeText on mount', () => {
+ const onChangeTextMock = jest.fn()
+ render()
+ expect(onChangeTextMock).not.toHaveBeenCalled()
+ })
test('should renders correctly with an accessory view', () => {
const container = render(
-
-