
* Minor fixes for intl messages * Add esbuild-loader * switch from babel to esbuild-loader * use formatjs enforce-id linter * Generate ids for intl messages * id format defined by idInterpolationPattern * Modify intl messages extraction * remove react-intl-translations-manager * remove transpile-tx.js * use formatjs cli * Modify defaultMessages.json * modify ids in defaultMessages.json with defined idInterpolationPattern * Fix errors * Fix page crash * Use babel to transpile tests * Fix useStateFromProps * Improve render count * Add test to useStateFromProps * Fix reloading state buh * Do not check if form with channels is dirty * Stop blocking save if form has not changed * Remove debug code * Fix form disabling * Fix variant selection checkbox onClick * Update translations * Update messages * Use esbuild to build storybook Co-authored-by: Bartłomiej Wiaduch <tukan2can@gmail.com> Co-authored-by: Jakub Majorek <majorek.jakub@gmail.com>
47 lines
1 KiB
TypeScript
47 lines
1 KiB
TypeScript
import { act, renderHook } from "@testing-library/react-hooks";
|
|
|
|
import useStateFromProps from "./useStateFromProps";
|
|
|
|
function setupHook() {
|
|
return renderHook(useStateFromProps, {
|
|
initialProps: {
|
|
a: 0
|
|
}
|
|
});
|
|
}
|
|
|
|
describe("useStateFromProps", () => {
|
|
it("updates itself if props changed", () => {
|
|
const hook = setupHook();
|
|
|
|
hook.rerender({ a: 1 });
|
|
|
|
expect(hook.result.current[0].a).toBe(1);
|
|
});
|
|
|
|
it("updates if called setState", () => {
|
|
const hook = setupHook();
|
|
|
|
act(() => hook.result.current[1]({ a: 1 }));
|
|
|
|
expect(hook.result.current[0].a).toBe(1);
|
|
});
|
|
|
|
it("does not update if props stay the same", () => {
|
|
const hook = setupHook();
|
|
|
|
act(() => hook.result.current[1]({ a: 1 }));
|
|
hook.rerender({ a: 0 });
|
|
|
|
expect(hook.result.current[0].a).toBe(1);
|
|
});
|
|
|
|
it("update if called setState and then props changed", () => {
|
|
const hook = setupHook();
|
|
|
|
act(() => hook.result.current[1]({ a: 1 }));
|
|
hook.rerender({ a: 2 });
|
|
|
|
expect(hook.result.current[0].a).toBe(2);
|
|
});
|
|
});
|