Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/bhovhannes/additween-mocks
Mocks for the additween animation library
https://github.com/bhovhannes/additween-mocks
Last synced: 15 days ago
JSON representation
Mocks for the additween animation library
- Host: GitHub
- URL: https://github.com/bhovhannes/additween-mocks
- Owner: bhovhannes
- License: mit
- Created: 2016-12-27T10:18:10.000Z (almost 8 years ago)
- Default Branch: main
- Last Pushed: 2024-04-14T09:23:32.000Z (7 months ago)
- Last Synced: 2024-04-14T09:53:30.042Z (7 months ago)
- Language: TypeScript
- Size: 3.27 MB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# additween-mocks
[![NPM version][npm-version-image]][npm-url] [![NPM downloads][npm-downloads-image]][npm-url] [![MIT License][license-image]][license-url] [![Coverage][codecov-image]][codecov-url]
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
```bash
npm install additween-mocks --save
```## Usage example
```javascript
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)
[license-image]: http://img.shields.io/badge/license-MIT-blue.svg?style=flat
[license-url]: LICENSE
[npm-url]: https://www.npmjs.org/package/additween-mocks
[npm-version-image]: https://img.shields.io/npm/v/additween-mocks.svg?style=flat
[npm-downloads-image]: https://img.shields.io/npm/dm/additween-mocks.svg?style=flat
[codecov-url]: https://codecov.io/gh/bhovhannes/additween-mocks
[codecov-image]: https://img.shields.io/codecov/c/github/bhovhannes/additween-mocks.svg