Animated-test.js 23.4 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794
/**
 * Copyright (c) 2015-present, Facebook, Inc.
 * All rights reserved.
 *
 * This source code is licensed under the BSD-style license found in the
 * LICENSE file in the root directory of this source tree. An additional grant
 * of patent rights can be found in the PATENTS file in the same directory.
 *
 * @emails oncall+react_native
 */
'use strict';

var Animated = require('Animated');
describe('Animated tests', () => {
  beforeEach(() => {
    jest.resetModules();
  });

  describe('Animated', () => {

    it('works end to end', () => {
      var anim = new Animated.Value(0);

      var callback = jest.fn();

      var node = new Animated.__PropsOnlyForTests({
        style: {
          backgroundColor: 'red',
          opacity: anim,
          transform: [
            {translateX: anim.interpolate({
              inputRange: [0, 1],
              outputRange: [100, 200],
            })},
            {scale: anim},
          ],
          shadowOffset: {
            width: anim,
            height: anim,
          },
        }
      }, callback);

      expect(anim.__getChildren().length).toBe(3);

      expect(node.__getValue()).toEqual({
        style: {
          backgroundColor: 'red',
          opacity: 0,
          transform: [
            {translateX: 100},
            {scale: 0},
          ],
          shadowOffset: {
            width: 0,
            height: 0,
          },
        },
      });

      anim.setValue(0.5);

      expect(callback).toBeCalled();

      expect(node.__getValue()).toEqual({
        style: {
          backgroundColor: 'red',
          opacity: 0.5,
          transform: [
            {translateX: 150},
            {scale: 0.5},
          ],
          shadowOffset: {
            width: 0.5,
            height: 0.5,
          },
        },
      });

      node.__detach();
      expect(anim.__getChildren().length).toBe(0);

      anim.setValue(1);
      expect(callback.mock.calls.length).toBe(1);
    });

    it('does not detach on updates', () => {
      var anim = new Animated.Value(0);
      anim.__detach = jest.fn();

      var c = new Animated.View();
      c.props = {
        style: {
          opacity: anim,
        },
      };
      c.UNSAFE_componentWillMount();

      expect(anim.__detach).not.toBeCalled();
      c._component = {};
      c.UNSAFE_componentWillReceiveProps({
        style: {
          opacity: anim,
        },
      });
      expect(anim.__detach).not.toBeCalled();

      c.componentWillUnmount();
      expect(anim.__detach).toBeCalled();
    });


    it('stops animation when detached', () => {
      var anim = new Animated.Value(0);
      var callback = jest.fn();

      var c = new Animated.View();
      c.props = {
        style: {
          opacity: anim,
        },
      };
      c.UNSAFE_componentWillMount();

      Animated.timing(anim, {toValue: 10, duration: 1000}).start(callback);
      c._component = {};
      c.componentWillUnmount();

      expect(callback).toBeCalledWith({finished: false});
      expect(callback).toBeCalledWith({finished: false});
    });

    it('triggers callback when spring is at rest', () => {
      var anim = new Animated.Value(0);
      var callback = jest.fn();
      Animated.spring(anim, {toValue: 0, velocity: 0}).start(callback);
      expect(callback).toBeCalled();
    });

    it('send toValue when an underdamped spring stops', () => {
      var anim = new Animated.Value(0);
      var listener = jest.fn();
      anim.addListener(listener);
      Animated.spring(anim, {toValue: 15}).start();
      jest.runAllTimers();
      var lastValue = listener.mock.calls[listener.mock.calls.length - 2][0].value;
      expect(lastValue).not.toBe(15);
      expect(lastValue).toBeCloseTo(15);
      expect(anim.__getValue()).toBe(15);
    });

    it('send toValue when a critically damped spring stops', () => {
      var anim = new Animated.Value(0);
      var listener = jest.fn();
      anim.addListener(listener);
      Animated.spring(anim, {stiffness: 8000, damping: 2000, toValue: 15}).start();
      jest.runAllTimers();
      var lastValue = listener.mock.calls[listener.mock.calls.length - 2][0].value;
      expect(lastValue).not.toBe(15);
      expect(lastValue).toBeCloseTo(15);
      expect(anim.__getValue()).toBe(15);
    });

    it('convert to JSON', () => {
      expect(JSON.stringify(new Animated.Value(10))).toBe('10');
    });
  });


  describe('Animated Sequence', () => {

    it('works with an empty sequence', () => {
      var cb = jest.fn();
      Animated.sequence([]).start(cb);
      expect(cb).toBeCalledWith({finished: true});
    });

    it('sequences well', () => {
      var anim1 = {start: jest.fn()};
      var anim2 = {start: jest.fn()};
      var cb = jest.fn();

      var seq = Animated.sequence([anim1, anim2]);

      expect(anim1.start).not.toBeCalled();
      expect(anim2.start).not.toBeCalled();

      seq.start(cb);

      expect(anim1.start).toBeCalled();
      expect(anim2.start).not.toBeCalled();
      expect(cb).not.toBeCalled();

      anim1.start.mock.calls[0][0]({finished: true});

      expect(anim2.start).toBeCalled();
      expect(cb).not.toBeCalled();

      anim2.start.mock.calls[0][0]({finished: true});
      expect(cb).toBeCalledWith({finished: true});
    });

    it('supports interrupting sequence', () => {
      var anim1 = {start: jest.fn()};
      var anim2 = {start: jest.fn()};
      var cb = jest.fn();

      Animated.sequence([anim1, anim2]).start(cb);

      anim1.start.mock.calls[0][0]({finished: false});

      expect(anim1.start).toBeCalled();
      expect(anim2.start).not.toBeCalled();
      expect(cb).toBeCalledWith({finished: false});
    });

    it('supports stopping sequence', () => {
      var anim1 = {start: jest.fn(), stop: jest.fn()};
      var anim2 = {start: jest.fn(), stop: jest.fn()};
      var cb = jest.fn();

      var seq = Animated.sequence([anim1, anim2]);
      seq.start(cb);
      seq.stop();

      expect(anim1.stop).toBeCalled();
      expect(anim2.stop).not.toBeCalled();
      expect(cb).not.toBeCalled();

      anim1.start.mock.calls[0][0]({finished: false});

      expect(cb).toBeCalledWith({finished: false});
    });
  });

  describe('Animated Loop', () => {

    it('loops indefinitely if config not specified', () => {
      var animation = {start: jest.fn(), reset: jest.fn(), _isUsingNativeDriver: () => false};
      var cb = jest.fn();

      var loop = Animated.loop(animation);

      expect(animation.start).not.toBeCalled();

      loop.start(cb);

      expect(animation.start).toBeCalled();
      expect(animation.reset).toHaveBeenCalledTimes(1);
      expect(cb).not.toBeCalled();

      animation.start.mock.calls[0][0]({finished: true}); // End of loop 1
      expect(animation.reset).toHaveBeenCalledTimes(2);
      expect(cb).not.toBeCalled();

      animation.start.mock.calls[0][0]({finished: true}); // End of loop 2
      expect(animation.reset).toHaveBeenCalledTimes(3);
      expect(cb).not.toBeCalled();

      animation.start.mock.calls[0][0]({finished: true}); // End of loop 3
      expect(animation.reset).toHaveBeenCalledTimes(4);
      expect(cb).not.toBeCalled();
    });

    it('loops indefinitely if iterations is -1', () => {
      var animation = {start: jest.fn(), reset: jest.fn(), _isUsingNativeDriver: () => false};
      var cb = jest.fn();

      var loop = Animated.loop(animation, { iterations: -1 });

      expect(animation.start).not.toBeCalled();

      loop.start(cb);

      expect(animation.start).toBeCalled();
      expect(animation.reset).toHaveBeenCalledTimes(1);
      expect(cb).not.toBeCalled();

      animation.start.mock.calls[0][0]({finished: true}); // End of loop 1
      expect(animation.reset).toHaveBeenCalledTimes(2);
      expect(cb).not.toBeCalled();

      animation.start.mock.calls[0][0]({finished: true}); // End of loop 2
      expect(animation.reset).toHaveBeenCalledTimes(3);
      expect(cb).not.toBeCalled();

      animation.start.mock.calls[0][0]({finished: true}); // End of loop 3
      expect(animation.reset).toHaveBeenCalledTimes(4);
      expect(cb).not.toBeCalled();
    });

    it('loops indefinitely if iterations not specified', () => {
      var animation = {start: jest.fn(), reset: jest.fn(), _isUsingNativeDriver: () => false};
      var cb = jest.fn();

      var loop = Animated.loop(animation, { anotherKey: 'value' });

      expect(animation.start).not.toBeCalled();

      loop.start(cb);

      expect(animation.start).toBeCalled();
      expect(animation.reset).toHaveBeenCalledTimes(1);
      expect(cb).not.toBeCalled();

      animation.start.mock.calls[0][0]({finished: true}); // End of loop 1
      expect(animation.reset).toHaveBeenCalledTimes(2);
      expect(cb).not.toBeCalled();

      animation.start.mock.calls[0][0]({finished: true}); // End of loop 2
      expect(animation.reset).toHaveBeenCalledTimes(3);
      expect(cb).not.toBeCalled();

      animation.start.mock.calls[0][0]({finished: true}); // End of loop 3
      expect(animation.reset).toHaveBeenCalledTimes(4);
      expect(cb).not.toBeCalled();
    });

    it('loops three times if iterations is 3', () => {
      var animation = {start: jest.fn(), reset: jest.fn(), _isUsingNativeDriver: () => false};
      var cb = jest.fn();

      var loop = Animated.loop(animation, { iterations: 3 });

      expect(animation.start).not.toBeCalled();

      loop.start(cb);

      expect(animation.start).toBeCalled();
      expect(animation.reset).toHaveBeenCalledTimes(1);
      expect(cb).not.toBeCalled();

      animation.start.mock.calls[0][0]({finished: true}); // End of loop 1
      expect(animation.reset).toHaveBeenCalledTimes(2);
      expect(cb).not.toBeCalled();

      animation.start.mock.calls[0][0]({finished: true}); // End of loop 2
      expect(animation.reset).toHaveBeenCalledTimes(3);
      expect(cb).not.toBeCalled();

      animation.start.mock.calls[0][0]({finished: true}); // End of loop 3
      expect(animation.reset).toHaveBeenCalledTimes(3);
      expect(cb).toBeCalledWith({finished: true});
    });

    it('does not loop if iterations is 1', () => {
      var animation = {start: jest.fn(), reset: jest.fn(), _isUsingNativeDriver: () => false};
      var cb = jest.fn();

      var loop = Animated.loop(animation, { iterations: 1 });

      expect(animation.start).not.toBeCalled();

      loop.start(cb);

      expect(animation.start).toBeCalled();
      expect(cb).not.toBeCalled();

      animation.start.mock.calls[0][0]({finished: true}); // End of loop 1
      expect(cb).toBeCalledWith({finished: true});
    });

    it('does not animate if iterations is 0', () => {
      var animation = {start: jest.fn(), reset: jest.fn(), _isUsingNativeDriver: () => false};
      var cb = jest.fn();

      var loop = Animated.loop(animation, { iterations: 0 });

      expect(animation.start).not.toBeCalled();

      loop.start(cb);

      expect(animation.start).not.toBeCalled();
      expect(cb).toBeCalledWith({finished: true});
    });

    it('supports interrupting an indefinite loop', () => {
      var animation = {start: jest.fn(), reset: jest.fn(), _isUsingNativeDriver: () => false};
      var cb = jest.fn();

      Animated.loop(animation).start(cb);
      expect(animation.start).toBeCalled();
      expect(animation.reset).toHaveBeenCalledTimes(1);
      expect(cb).not.toBeCalled();

      animation.start.mock.calls[0][0]({finished: true}); // End of loop 1
      expect(animation.reset).toHaveBeenCalledTimes(2);
      expect(cb).not.toBeCalled();

      animation.start.mock.calls[0][0]({finished: false}); // Interrupt loop
      expect(animation.reset).toHaveBeenCalledTimes(2);
      expect(cb).toBeCalledWith({finished: false});
    });

    it('supports stopping loop', () => {
      var animation = {start: jest.fn(), stop: jest.fn(), reset: jest.fn(), _isUsingNativeDriver: () => false};
      var cb = jest.fn();

      var loop = Animated.loop(animation);
      loop.start(cb);
      loop.stop();

      expect(animation.start).toBeCalled();
      expect(animation.reset).toHaveBeenCalledTimes(1);
      expect(animation.stop).toBeCalled();

      animation.start.mock.calls[0][0]({finished: false}); // Interrupt loop
      expect(animation.reset).toHaveBeenCalledTimes(1);
      expect(cb).toBeCalledWith({finished: false});
    });
  });

  describe('Animated Parallel', () => {

    it('works with an empty parallel', () => {
      var cb = jest.fn();
      Animated.parallel([]).start(cb);
      expect(cb).toBeCalledWith({finished: true});
    });

    it('works with an empty element in array', () => {
      var anim1 = {start: jest.fn()};
      var cb = jest.fn();
      Animated.parallel([null, anim1]).start(cb);

      expect(anim1.start).toBeCalled();
      anim1.start.mock.calls[0][0]({finished: true});

      expect(cb).toBeCalledWith({finished: true});
    });

    it('parellelizes well', () => {
      var anim1 = {start: jest.fn()};
      var anim2 = {start: jest.fn()};
      var cb = jest.fn();

      var par = Animated.parallel([anim1, anim2]);

      expect(anim1.start).not.toBeCalled();
      expect(anim2.start).not.toBeCalled();

      par.start(cb);

      expect(anim1.start).toBeCalled();
      expect(anim2.start).toBeCalled();
      expect(cb).not.toBeCalled();

      anim1.start.mock.calls[0][0]({finished: true});
      expect(cb).not.toBeCalled();

      anim2.start.mock.calls[0][0]({finished: true});
      expect(cb).toBeCalledWith({finished: true});
    });

    it('supports stopping parallel', () => {
      var anim1 = {start: jest.fn(), stop: jest.fn()};
      var anim2 = {start: jest.fn(), stop: jest.fn()};
      var cb = jest.fn();

      var seq = Animated.parallel([anim1, anim2]);
      seq.start(cb);
      seq.stop();

      expect(anim1.stop).toBeCalled();
      expect(anim2.stop).toBeCalled();
      expect(cb).not.toBeCalled();

      anim1.start.mock.calls[0][0]({finished: false});
      expect(cb).not.toBeCalled();

      anim2.start.mock.calls[0][0]({finished: false});
      expect(cb).toBeCalledWith({finished: false});
    });


    it('does not call stop more than once when stopping', () => {
      var anim1 = {start: jest.fn(), stop: jest.fn()};
      var anim2 = {start: jest.fn(), stop: jest.fn()};
      var anim3 = {start: jest.fn(), stop: jest.fn()};
      var cb = jest.fn();

      var seq = Animated.parallel([anim1, anim2, anim3]);
      seq.start(cb);

      anim1.start.mock.calls[0][0]({finished: false});

      expect(anim1.stop.mock.calls.length).toBe(0);
      expect(anim2.stop.mock.calls.length).toBe(1);
      expect(anim3.stop.mock.calls.length).toBe(1);

      anim2.start.mock.calls[0][0]({finished: false});

      expect(anim1.stop.mock.calls.length).toBe(0);
      expect(anim2.stop.mock.calls.length).toBe(1);
      expect(anim3.stop.mock.calls.length).toBe(1);

      anim3.start.mock.calls[0][0]({finished: false});

      expect(anim1.stop.mock.calls.length).toBe(0);
      expect(anim2.stop.mock.calls.length).toBe(1);
      expect(anim3.stop.mock.calls.length).toBe(1);
    });
  });

  describe('Animated delays', () => {
    it('should call anim after delay in sequence', () => {
      var anim = {start: jest.fn(), stop: jest.fn()};
      var cb = jest.fn();
      Animated.sequence([
        Animated.delay(1000),
        anim,
      ]).start(cb);
      jest.runAllTimers();
      expect(anim.start.mock.calls.length).toBe(1);
      expect(cb).not.toBeCalled();
      anim.start.mock.calls[0][0]({finished: true});
      expect(cb).toBeCalledWith({finished: true});
    });
    it('should run stagger to end', () => {
      var cb = jest.fn();
      Animated.stagger(1000, [
        Animated.delay(1000),
        Animated.delay(1000),
        Animated.delay(1000),
      ]).start(cb);
      jest.runAllTimers();
      expect(cb).toBeCalledWith({finished: true});
    });
  });

  describe('Animated Events', () => {
    it('should map events', () => {
      var value = new Animated.Value(0);
      var handler = Animated.event(
        [null, {state: {foo: value}}],
      );
      handler({bar: 'ignoreBar'}, {state: {baz: 'ignoreBaz', foo: 42}});
      expect(value.__getValue()).toBe(42);
    });
    it('should call listeners', () => {
      var value = new Animated.Value(0);
      var listener = jest.fn();
      var handler = Animated.event(
        [{foo: value}],
        {listener},
      );
      handler({foo: 42});
      expect(value.__getValue()).toBe(42);
      expect(listener.mock.calls.length).toBe(1);
      expect(listener).toBeCalledWith({foo: 42});
    });
    it('should call forked event listeners', () => {
      var value = new Animated.Value(0);
      var listener = jest.fn();
      var handler = Animated.event(
        [{foo: value}],
        {listener},
      );
      var listener2 = jest.fn();
      var forkedHandler = Animated.forkEvent(handler, listener2);
      forkedHandler({foo: 42});
      expect(value.__getValue()).toBe(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});
    });
  });

  describe('Animated Interactions', () => {
    /*eslint-disable no-shadow*/
    var Animated;
    /*eslint-enable*/
    var InteractionManager;

    beforeEach(() => {
      jest.mock('InteractionManager');
      Animated = require('Animated');
      InteractionManager = require('InteractionManager');
    });

    afterEach(()=> {
      jest.unmock('InteractionManager');
    });

    it('registers an interaction by default', () => {
      InteractionManager.createInteractionHandle.mockReturnValue(777);

      var value = new Animated.Value(0);
      var callback = jest.fn();
      Animated.timing(value, {
        toValue: 100,
        duration: 100,
      }).start(callback);
      jest.runAllTimers();

      expect(InteractionManager.createInteractionHandle).toBeCalled();
      expect(InteractionManager.clearInteractionHandle).toBeCalledWith(777);
      expect(callback).toBeCalledWith({finished: true});
    });

    it('does not register an interaction when specified', () => {
      var value = new Animated.Value(0);
      var callback = jest.fn();
      Animated.timing(value, {
        toValue: 100,
        duration: 100,
        isInteraction: false,
      }).start(callback);
      jest.runAllTimers();

      expect(InteractionManager.createInteractionHandle).not.toBeCalled();
      expect(InteractionManager.clearInteractionHandle).not.toBeCalled();
      expect(callback).toBeCalledWith({finished: true});
    });
  });

  describe('Animated Tracking', () => {
    it('should track values', () => {
      var value1 = new Animated.Value(0);
      var value2 = new Animated.Value(0);
      Animated.timing(value2, {
        toValue: value1,
        duration: 0,
      }).start();
      value1.setValue(42);
      expect(value2.__getValue()).toBe(42);
      value1.setValue(7);
      expect(value2.__getValue()).toBe(7);
    });

    it('should track interpolated values', () => {
      var value1 = new Animated.Value(0);
      var value2 = new Animated.Value(0);
      Animated.timing(value2, {
        toValue: value1.interpolate({
          inputRange: [0, 2],
          outputRange: [0, 1]
        }),
        duration: 0,
      }).start();
      value1.setValue(42);
      expect(value2.__getValue()).toBe(42 / 2);
    });

    it('should stop tracking when animated', () => {
      var value1 = new Animated.Value(0);
      var value2 = new Animated.Value(0);
      Animated.timing(value2, {
        toValue: value1,
        duration: 0,
      }).start();
      value1.setValue(42);
      expect(value2.__getValue()).toBe(42);
      Animated.timing(value2, {
        toValue: 7,
        duration: 0,
      }).start();
      value1.setValue(1492);
      expect(value2.__getValue()).toBe(7);
    });
  });

  describe('Animated Vectors', () => {
    it('should animate vectors', () => {
      var vec = new Animated.ValueXY();

      var callback = jest.fn();

      var node = new Animated.__PropsOnlyForTests({
        style: {
          opacity: vec.x.interpolate({
            inputRange: [0, 42],
            outputRange: [0.2, 0.8],
          }),
          transform: vec.getTranslateTransform(),
          ...vec.getLayout(),
        }
      }, callback);

      expect(node.__getValue()).toEqual({
        style: {
          opacity: 0.2,
          transform: [
            {translateX: 0},
            {translateY: 0},
          ],
          left: 0,
          top: 0,
        },
      });

      vec.setValue({x: 42, y: 1492});

      expect(callback.mock.calls.length).toBe(2); // once each for x, y

      expect(node.__getValue()).toEqual({
        style: {
          opacity: 0.8,
          transform: [
            {translateX: 42},
            {translateY: 1492},
          ],
          left: 42,
          top: 1492,
        },
      });

      node.__detach();

      vec.setValue({x: 1, y: 1});
      expect(callback.mock.calls.length).toBe(2);
    });

    it('should track vectors', () => {
      var value1 = new Animated.ValueXY();
      var value2 = new Animated.ValueXY();
      Animated.timing(value2, {
        toValue: value1,
        duration: 0,
      }).start();
      value1.setValue({x: 42, y: 1492});
      expect(value2.__getValue()).toEqual({x: 42, y: 1492});

      // Make sure tracking keeps working (see stopTogether in ParallelConfig used
      // by maybeVectorAnim).
      value1.setValue({x: 3, y: 4});
      expect(value2.__getValue()).toEqual({x: 3, y: 4});
    });

    it('should track with springs', () => {
      var value1 = new Animated.ValueXY();
      var value2 = new Animated.ValueXY();
      Animated.spring(value2, {
        toValue: value1,
        tension: 3000, // faster spring for faster test
        friction: 60,
      }).start();
      value1.setValue({x: 1, y: 1});
      jest.runAllTimers();
      expect(Math.round(value2.__getValue().x)).toEqual(1);
      expect(Math.round(value2.__getValue().y)).toEqual(1);
      value1.setValue({x: 2, y: 2});
      jest.runAllTimers();
      expect(Math.round(value2.__getValue().x)).toEqual(2);
      expect(Math.round(value2.__getValue().y)).toEqual(2);
    });
  });

  describe('Animated Listeners', () => {
    it('should get updates', () => {
      var value1 = new Animated.Value(0);
      var listener = jest.fn();
      var id = value1.addListener(listener);
      value1.setValue(42);
      expect(listener.mock.calls.length).toBe(1);
      expect(listener).toBeCalledWith({value: 42});
      expect(value1.__getValue()).toBe(42);
      value1.setValue(7);
      expect(listener.mock.calls.length).toBe(2);
      expect(listener).toBeCalledWith({value: 7});
      expect(value1.__getValue()).toBe(7);
      value1.removeListener(id);
      value1.setValue(1492);
      expect(listener.mock.calls.length).toBe(2);
      expect(value1.__getValue()).toBe(1492);
    });

    it('should removeAll', () => {
      var value1 = new Animated.Value(0);
      var listener = jest.fn();
      [1,2,3,4].forEach(() => value1.addListener(listener));
      value1.setValue(42);
      expect(listener.mock.calls.length).toBe(4);
      expect(listener).toBeCalledWith({value: 42});
      value1.removeAllListeners();
      value1.setValue(7);
      expect(listener.mock.calls.length).toBe(4);
    });
  });

  describe('Animated Diff Clamp', () => {
    it('should get the proper value', () => {
      const inputValues = [0, 20, 40, 30, 0, -40, -10, -20, 0];
      const expectedValues = [0, 20, 20, 10, 0, 0, 20, 10, 20];
      const value = new Animated.Value(0);
      const diffClampValue = Animated.diffClamp(value, 0, 20);
      for (let i = 0; i < inputValues.length; i++) {
        value.setValue(inputValues[i]);
        expect(diffClampValue.__getValue()).toBe(expectedValues[i]);
      }
    });
  });
});