uno-react
Version:
Common functions, and hooks for React.
58 lines (57 loc) • 2.06 kB
JavaScript
;
/**
* @jest-environment jsdom
*/
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const react_1 = require("@testing-library/react");
const useStateForModel_1 = __importDefault(require("./useStateForModel"));
test('Should keep updated the values of a model that are related to an input(event) handling the inputs onChange calls', () => {
const initialValue = {
id: 1,
name: 'John',
lastName: 'Doe',
};
const { result } = (0, react_1.renderHook)(() => (0, useStateForModel_1.default)(initialValue));
const eventInputName = {
target: { value: 'value name', name: 'name' },
};
const eventInputLastName = {
target: { value: 'value last name', name: 'lastName' },
};
(0, react_1.act)(() => {
result.current[1](eventInputName);
});
(0, react_1.act)(() => {
result.current[1](eventInputLastName);
});
initialValue.name = 'value name';
initialValue.lastName = 'value last name';
expect(result.current[0]).toStrictEqual(initialValue);
});
test('Should keep updated the values of a model that are related to an input(event) handling the inputs onChange calls adding new property if does not exist.', () => {
const initialValue = {
id: 1,
name: 'John',
lastName: 'Doe',
bubbles: undefined,
};
const { result } = (0, react_1.renderHook)(() => (0, useStateForModel_1.default)(initialValue));
const eventInputName = {
target: { value: 'value name', name: 'name' },
};
const eventInputLastName = {
bubbles: false,
};
(0, react_1.act)(() => {
result.current[1](eventInputName);
});
(0, react_1.act)(() => {
result.current[1](eventInputLastName);
});
initialValue.name = 'value name';
initialValue.bubbles = false;
expect(result.current[0]).toStrictEqual(initialValue);
});