46 lines
1.7 KiB
JavaScript
46 lines
1.7 KiB
JavaScript
|
"use strict";
|
||
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||
|
var tslib_1 = require("tslib");
|
||
|
var React = require("react");
|
||
|
var safeRequestAnimationFrame_1 = require("./safeRequestAnimationFrame");
|
||
|
var enzyme_1 = require("enzyme");
|
||
|
describe('safeRequestAnimationFrame', function () {
|
||
|
var rafCalled = false;
|
||
|
var Foo = /** @class */ (function (_super) {
|
||
|
tslib_1.__extends(Foo, _super);
|
||
|
function Foo(props) {
|
||
|
var _this = _super.call(this, props) || this;
|
||
|
_this._raf = (0, safeRequestAnimationFrame_1.safeRequestAnimationFrame)(_this);
|
||
|
return _this;
|
||
|
}
|
||
|
Foo.prototype.render = function () {
|
||
|
return React.createElement("div", null, "Hello");
|
||
|
};
|
||
|
Foo.prototype.componentDidMount = function () {
|
||
|
this._raf(function () { return (rafCalled = true); });
|
||
|
};
|
||
|
return Foo;
|
||
|
}(React.Component));
|
||
|
beforeEach(function () {
|
||
|
rafCalled = false;
|
||
|
jest.useFakeTimers();
|
||
|
});
|
||
|
afterEach(function () {
|
||
|
jest.runOnlyPendingTimers();
|
||
|
jest.useRealTimers();
|
||
|
});
|
||
|
it('can request animation frame', function () {
|
||
|
(0, enzyme_1.mount)(React.createElement(Foo, null));
|
||
|
expect(rafCalled).toEqual(false);
|
||
|
jest.runOnlyPendingTimers();
|
||
|
expect(rafCalled).toEqual(true);
|
||
|
});
|
||
|
it('can cancel request animation frame', function () {
|
||
|
var wrapper = (0, enzyme_1.mount)(React.createElement(Foo, null));
|
||
|
expect(rafCalled).toEqual(false);
|
||
|
wrapper.unmount();
|
||
|
jest.runOnlyPendingTimers();
|
||
|
expect(rafCalled).toEqual(false);
|
||
|
});
|
||
|
});
|
||
|
//# sourceMappingURL=safeRequestAnimationFrame.test.js.map
|