forked from necolas/react-native-web
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add test that exhibits the behavior causing necolas#1665
- Loading branch information
1 parent
4a70300
commit 10aadfc
Showing
8 changed files
with
282 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
packages/react-native-web/src/exports/Pressable/__tests__/index-test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* eslint-env jasmine, jest */ | ||
/* eslint-disable react/jsx-no-bind */ | ||
|
||
import React from 'react'; | ||
import { render } from '@testing-library/react'; | ||
import TouchableOpacity from '../'; | ||
|
||
describe('components/Pressable', () => { | ||
test('ref function is called when ref changes', () => { | ||
const refMock = jest.fn(); | ||
const otherRefMock = jest.fn(); | ||
|
||
const { rerender } = render(<TouchableOpacity ref={refMock} />); | ||
expect(refMock).toHaveBeenCalled(); | ||
|
||
rerender(<TouchableOpacity ref={otherRefMock} />) | ||
expect(otherRefMock).toHaveBeenCalled(); | ||
}); | ||
|
||
test('ref function is not called every render', () => { | ||
const refMock = jest.fn(); | ||
|
||
const { rerender } = render(<TouchableOpacity ref={refMock} />); | ||
expect(refMock).toHaveBeenCalledTimes(1); | ||
|
||
rerender(<TouchableOpacity ref={refMock} />); | ||
expect(refMock).toHaveBeenCalledTimes(1); | ||
}); | ||
|
||
test('ref function is not called on prop changes', () => { | ||
const refMock = jest.fn(); | ||
|
||
const { rerender } = render(<TouchableOpacity ref={refMock} testID={'foo'} />); | ||
expect(refMock).toHaveBeenCalledTimes(1); | ||
|
||
rerender(<TouchableOpacity ref={refMock} testID={'bar'} />); | ||
expect(refMock).toHaveBeenCalledTimes(1); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
packages/react-native-web/src/exports/TouchableHighlight/__tests__/index-test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* eslint-env jasmine, jest */ | ||
/* eslint-disable react/jsx-no-bind */ | ||
|
||
import React from 'react'; | ||
import { render } from '@testing-library/react'; | ||
import TouchableHighlight from '../'; | ||
import View from '../../View'; | ||
|
||
describe('components/TouchableHighlight', () => { | ||
test('ref function is called when ref changes', () => { | ||
const refMock = jest.fn(); | ||
const otherRefMock = jest.fn(); | ||
|
||
const { rerender } = render(<TouchableHighlight ref={refMock}><View /></TouchableHighlight>); | ||
expect(refMock).toHaveBeenCalled(); | ||
|
||
rerender(<TouchableHighlight ref={otherRefMock}><View /></TouchableHighlight>) | ||
expect(otherRefMock).toHaveBeenCalled(); | ||
}); | ||
|
||
test('ref function is not called every render', () => { | ||
const refMock = jest.fn(); | ||
|
||
const { rerender } = render(<TouchableHighlight ref={refMock}><View /></TouchableHighlight>); | ||
expect(refMock).toHaveBeenCalledTimes(1); | ||
|
||
rerender(<TouchableHighlight ref={refMock}><View /></TouchableHighlight>); | ||
expect(refMock).toHaveBeenCalledTimes(1); | ||
}); | ||
|
||
test('ref function is not called on prop changes', () => { | ||
const refMock = jest.fn(); | ||
|
||
const { rerender } = render(<TouchableHighlight ref={refMock} testID={'foo'}><View /></TouchableHighlight>); | ||
expect(refMock).toHaveBeenCalledTimes(1); | ||
|
||
rerender(<TouchableHighlight ref={refMock} testID={'bar'}><View /></TouchableHighlight>); | ||
expect(refMock).toHaveBeenCalledTimes(1); | ||
}); | ||
}); |
39 changes: 39 additions & 0 deletions
39
packages/react-native-web/src/exports/TouchableOpacity/__tests__/index-test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* eslint-env jasmine, jest */ | ||
/* eslint-disable react/jsx-no-bind */ | ||
|
||
import React from 'react'; | ||
import { render } from '@testing-library/react'; | ||
import TouchableOpacity from '../'; | ||
|
||
describe('components/TouchableOpacity', () => { | ||
test('ref function is called when ref changes', () => { | ||
const refMock = jest.fn(); | ||
const otherRefMock = jest.fn(); | ||
|
||
const { rerender } = render(<TouchableOpacity ref={refMock} />); | ||
expect(refMock).toHaveBeenCalled(); | ||
|
||
rerender(<TouchableOpacity ref={otherRefMock} />) | ||
expect(otherRefMock).toHaveBeenCalled(); | ||
}); | ||
|
||
test('ref function is not called every render', () => { | ||
const refMock = jest.fn(); | ||
|
||
const { rerender } = render(<TouchableOpacity ref={refMock} />); | ||
expect(refMock).toHaveBeenCalledTimes(1); | ||
|
||
rerender(<TouchableOpacity ref={refMock} />); | ||
expect(refMock).toHaveBeenCalledTimes(1); | ||
}); | ||
|
||
test('ref function is not called on prop changes', () => { | ||
const refMock = jest.fn(); | ||
|
||
const { rerender } = render(<TouchableOpacity ref={refMock} testID={'foo'} />); | ||
expect(refMock).toHaveBeenCalledTimes(1); | ||
|
||
rerender(<TouchableOpacity ref={refMock} testID={'bar'} />); | ||
expect(refMock).toHaveBeenCalledTimes(1); | ||
}); | ||
}); |
40 changes: 40 additions & 0 deletions
40
packages/react-native-web/src/exports/TouchableWithoutFeedback/__tests__/index-test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* eslint-env jasmine, jest */ | ||
/* eslint-disable react/jsx-no-bind */ | ||
|
||
import React from 'react'; | ||
import { render } from '@testing-library/react'; | ||
import TouchableWithoutFeedback from '../'; | ||
import View from '../../View'; | ||
|
||
describe('components/TouchableWithoutFeedback', () => { | ||
test('ref function is called when ref changes', () => { | ||
const refMock = jest.fn(); | ||
const otherRefMock = jest.fn(); | ||
|
||
const { rerender } = render(<TouchableWithoutFeedback ref={refMock}><View /></TouchableWithoutFeedback>); | ||
expect(refMock).toHaveBeenCalled(); | ||
|
||
rerender(<TouchableWithoutFeedback ref={otherRefMock}><View /></TouchableWithoutFeedback>) | ||
expect(otherRefMock).toHaveBeenCalled(); | ||
}); | ||
|
||
test('ref function is not called every render', () => { | ||
const refMock = jest.fn(); | ||
|
||
const { rerender } = render(<TouchableWithoutFeedback ref={refMock}><View /></TouchableWithoutFeedback>); | ||
expect(refMock).toHaveBeenCalledTimes(1); | ||
|
||
rerender(<TouchableWithoutFeedback ref={refMock}><View /></TouchableWithoutFeedback>); | ||
expect(refMock).toHaveBeenCalledTimes(1); | ||
}); | ||
|
||
test('ref function is not called on prop changes', () => { | ||
const refMock = jest.fn(); | ||
|
||
const { rerender } = render(<TouchableWithoutFeedback ref={refMock} testID={'foo'}><View /></TouchableWithoutFeedback>); | ||
expect(refMock).toHaveBeenCalledTimes(1); | ||
|
||
rerender(<TouchableWithoutFeedback ref={refMock} testID={'bar'}><View /></TouchableWithoutFeedback>); | ||
expect(refMock).toHaveBeenCalledTimes(1); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters