@vergiss/chooks
Version:
React hooks library
45 lines (41 loc) • 1.14 kB
JavaScript
;
import "core-js/modules/es.object.define-property";
Object.defineProperty(exports, "__esModule", {
value: true
});
var react_hooks_1 = require("@testing-library/react-hooks");
var index_1 = require("../index");
describe('useChangedProps', function () {
it('should be defined', function () {
expect(index_1.useChangedProps).toBeDefined();
});
it('should invoke callback', function () {
var props = {
name: 'coma'
};
var callback = jest.fn().mockReturnValue(void 0);
var hook = react_hooks_1.renderHook(function () {
return index_1.useChangedProps(props, callback);
}, {
initialProps: props
});
props = {
name: 'cc'
};
hook.rerender();
expect(callback).toBeCalledTimes(1);
});
it('should not invoke callback', function () {
var props = {
name: 'coma'
};
var callback = jest.fn().mockReturnValue(void 0);
var hook = react_hooks_1.renderHook(function () {
return index_1.useChangedProps(props, callback);
}, {
initialProps: props
});
hook.rerender();
expect(callback).toBeCalledTimes(0);
});
});