Add missing tests for Animated.forkEvent (#20111)
Summary: `forkEvent` is generally used to intercept an existing listener and add a new js listener to it, considering the original listener can be null/js/Animated.event(). I added tests to ensure the 3 cases of the implementation are all covered. Pull Request resolved: https://github.com/facebook/react-native/pull/20111 Differential Revision: D8817500 Pulled By: hramos fbshipit-source-id: 1a20b6f73e2d47bbefccd31378764909a45e89bb
This commit is contained in:
parent
78137bc31a
commit
f0d35904c9
|
@ -572,7 +572,7 @@ describe('Animated tests', () => {
|
|||
expect(listener.mock.calls.length).toBe(1);
|
||||
expect(listener).toBeCalledWith({foo: 42});
|
||||
});
|
||||
it('should call forked event listeners', () => {
|
||||
it('should call forked event listeners, with Animated.event() listener', () => {
|
||||
const value = new Animated.Value(0);
|
||||
const listener = jest.fn();
|
||||
const handler = Animated.event([{foo: value}], {listener});
|
||||
|
@ -585,6 +585,24 @@ describe('Animated tests', () => {
|
|||
expect(listener2.mock.calls.length).toBe(1);
|
||||
expect(listener2).toBeCalledWith({foo: 42});
|
||||
});
|
||||
it('should call forked event listeners, with js listener', () => {
|
||||
const listener = jest.fn();
|
||||
const listener2 = jest.fn();
|
||||
const forkedHandler = Animated.forkEvent(listener, listener2);
|
||||
forkedHandler({foo: 42});
|
||||
expect(listener.mock.calls.length).toBe(1);
|
||||
expect(listener).toBeCalledWith({foo: 42});
|
||||
expect(listener2.mock.calls.length).toBe(1);
|
||||
expect(listener2).toBeCalledWith({foo: 42});
|
||||
});
|
||||
it('should call forked event listeners, with undefined listener', () => {
|
||||
const listener = undefined;
|
||||
const listener2 = jest.fn();
|
||||
const forkedHandler = Animated.forkEvent(listener, listener2);
|
||||
forkedHandler({foo: 42});
|
||||
expect(listener2.mock.calls.length).toBe(1);
|
||||
expect(listener2).toBeCalledWith({foo: 42});
|
||||
});
|
||||
});
|
||||
|
||||
describe('Animated Interactions', () => {
|
||||
|
|
Loading…
Reference in New Issue