{"size": 1133, "ext": "js", "max_stars_repo_path": "test/utils/createSetInnerState.u.test.js", "max_stars_repo_name": "kasvtv/react-fun", "max_stars_repo_stars_event_min_datetime": "2019-06-01T19:59:15.000Z", "max_stars_repo_stars_event_max_datetime": "2019-06-01T19:59:15.000Z", "max_issues_repo_path": "test/utils/createSetInnerState.u.test.js", "max_issues_repo_name": "kasvtv/react-fun", "max_issues_repo_issues_event_min_datetime": "2020-09-04T22:41:59.000Z", "max_issues_repo_issues_event_max_datetime": "2021-05-09T00:38:58.000Z", "max_forks_repo_path": "test/utils/createSetInnerState.u.test.js", "max_forks_repo_name": "kasvtv/react-fun", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 1, "max_issues_count": 2, "max_forks_count": null, "avg_line_length": 31.4722222222, "max_line_length": 84, "alphanum_fraction": 0.6487202118}
import createSetInnerState from '../../utils/createSetInnerState';

describe('GIVEN createSetInnerState', () => {
	describe('WHEN called with a falsy argument', () => {
		it('THEN returns (objX) => this.setState(objX)', () => {
			const fn = createSetInnerState();
			const setState = jest.fn();
			const newState = Symbol('newState');
			fn.call({ setState }, newState);

			expect(setState).toHaveBeenCalledTimes(1);
			expect(setState).toHaveBeenCalledWith(newState);
		});
	});

	describe('WHEN called with a string s', () => {
		it('THEN returns (objX) => this.setState((objY) => {...objY.s, ...objX})', () => {
			const fn = createSetInnerState('new');
			const setState = jest.fn();
			const prevState = {
				new: {
					existing: Symbol('prevState.new.existing'),
				},
			};
			const newStateItem = { new: Symbol('newStateItem') };

			fn.call({ setState }, newStateItem);

			const newStateFn = setState.mock.calls[0][0];
			const newState = newStateFn(prevState);

			expect(newState.new).toHaveProperty('existing', prevState.new.existing);
			expect(newState.new).toHaveProperty('new', newStateItem.new);
		});
	});
});