{"size": 1006, "ext": "js", "max_stars_repo_path": "test/client.spec.js", "max_stars_repo_name": "SpainTrain/react-html-doc", "max_stars_repo_stars_event_min_datetime": "2015-10-25T22:31:44.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-02T14:35:55.000Z", "max_issues_repo_path": "test/client.spec.js", "max_issues_repo_name": "SpainTrain/react-html-doc", "max_issues_repo_issues_event_min_datetime": "2015-10-25T22:35:57.000Z", "max_issues_repo_issues_event_max_datetime": "2020-09-03T13:01:11.000Z", "max_forks_repo_path": "test/client.spec.js", "max_forks_repo_name": "SpainTrain/react-html-doc", "max_forks_repo_forks_event_min_datetime": "2016-04-18T07:54:30.000Z", "max_forks_repo_forks_event_max_datetime": "2021-04-21T08:14:56.000Z"}
{"max_stars_count": 188, "max_issues_count": 13, "max_forks_count": 22, "avg_line_length": 37.2592592593, "max_line_length": 104, "alphanum_fraction": 0.6908548708}
import { expect } from 'chai';

import { getUniversalStateFromScript } from '../src/client';
import { STATE_SCRIPT_ID, ERRORS } from '../src/constants';
import { renderAndGetQuerySelector } from './utils';


describe('Client', () => {
  it('getUniversalStateFromScript grabs state from dom', () => {
    const props = {
      universalState: { myState: true }
    };
    const qs = renderAndGetQuerySelector(props);
    const stateScript = qs(`script#${STATE_SCRIPT_ID}`);
    const parser = script => JSON.parse(script.text());
    const state = getUniversalStateFromScript(stateScript, parser);
    expect(state).to.deep.equal(props.universalState);
  });

  it('getUniversalStateFromScript throws helpful error if there\'s no state on the document', () => {
    const props = {};
    const qs = renderAndGetQuerySelector(props);
    const script = qs(`script#${STATE_SCRIPT_ID}`).html();
    expect(getUniversalStateFromScript.bind(null, script)).to.throw(new RegExp(ERRORS.STATE_NOT_FOUND));
  });
});
