Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

additween-mocks

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

additween-mocks

Mocks for the additween animation library

  • 3.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

additween-mocks

NPM version NPM downloads MIT License Coverage

Mocks for the additween animation library. It can be used with any testing framework (in the usage example below we use jasmine).

It works by replacing some methods of additween with its stub implementations, which allow to synchronously move animation internal clock forward.

How to install

npm install additween-mocks --save

Usage example

import { AdditiveTweening } from "additween";
import { AdditiveTweeningMock } from "additween-mocks";

describe("my great app", function () {
  let additiveTweeningMock = new AdditiveTweeningMock();
  beforeEach(function () {
    additiveTweeningMock = new AdditiveTweeningMock();
    additiveTweeningMock.install(AdditiveTweening);
  });

  afterEach(function () {
    additiveTweeningMock.uninstall(AdditiveTweening);
  });

  it("should animate perfectly", function () {
    // let's say clicking a button
    // will cause an animation with 2000ms duration
    // we assume there is a triggerClick method defined somewhere
    let btn = document.getElementById("byButton");
    triggerClick(btn);

    // let time go forward by 1000ms
    additiveTweeningMock.tick(1000);

    //now we can make assertions about animation state after half of time
    //expect(...)

    // let time go forward by another 1000ms
    additiveTweeningMock.tick(1000);

    //now we can make assertions about animation final state
    //expect(...)
  });
});

Mock API

mock = new AdditiveTweeningMock()

Creates a new instance of mocking library.

mock.install(AdditiveTweening)

Pass an AdditiveTweening constructor in order to patch its animation-related methods.

mock.uninstall(AdditiveTweening)

Restores original implementation of passed in AdditiveTweening.

mock.tick(duration)

Moves animation clock forward by duration msecs. Animation onRender callback will be called once after that. If duration is greater or equal than total animation duration, onFinish callback also will be called.

mock.reset()

Reset animation clock to its initial state.

License

MIT (http://www.opensource.org/licenses/mit-license.php)

Keywords

FAQs

Package last updated on 23 Nov 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc