From f0d35904c9a1454569bd4b797bec305c843f9bda Mon Sep 17 00:00:00 2001 From: slorber Date: Wed, 11 Jul 2018 22:27:11 -0700 Subject: [PATCH] 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 --- .../Animated/src/__tests__/Animated-test.js | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/Libraries/Animated/src/__tests__/Animated-test.js b/Libraries/Animated/src/__tests__/Animated-test.js index 1c2066bfdc5..6c5ef66b14a 100644 --- a/Libraries/Animated/src/__tests__/Animated-test.js +++ b/Libraries/Animated/src/__tests__/Animated-test.js @@ -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', () => {