{"size": 1310, "ext": "js", "max_stars_repo_path": "src/__test__/components/Error.test.js", "max_stars_repo_name": "andyChenAn/react-cnode-two", "max_stars_repo_stars_event_min_datetime": "2019-05-27T07:53:23.000Z", "max_stars_repo_stars_event_max_datetime": "2019-05-27T07:53:23.000Z", "max_issues_repo_path": "src/__test__/components/Error.test.js", "max_issues_repo_name": "andyChenAn/react-cnode-two", "max_issues_repo_issues_event_min_datetime": "2022-01-15T01:28:08.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-15T01:28:08.000Z", "max_forks_repo_path": "src/__test__/components/Error.test.js", "max_forks_repo_name": "andyChenAn/react-cnode-two", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 1, "max_issues_count": 1, "max_forks_count": null, "avg_line_length": 29.1111111111, "max_line_length": 86, "alphanum_fraction": 0.5664122137}
import React , { Component } from 'react';
import Enzyme , { shallow } from 'enzyme';
import Adapter from 'enzyme-adapter-react-16';
import Error from '../../components/Error/Error';
function setup1 () {
    const props = {
        error : {
            status : 404,
            statusText : 'Not Found'
        }
    };
    const enzymeWrapper = shallow(<Error {...props} />);
    return {
        props,
        enzymeWrapper
    }
};
function setup2 () {
    const props = {
        error : {
            status : 400,
            statusText : 'Bad Request'
        }
    };
    const enzymeWrapper = shallow(<Error {...props} />);
    return {
        props,
        enzymeWrapper
    }
}
Enzyme.configure({adapter : new Adapter()});
describe('测试Error组件' , () => {
    it('应该会渲染出status为404的Error组件' , () => {
        const { enzymeWrapper } = setup1();
        expect(enzymeWrapper.find('div.error-box').hasClass('error-box')).toBe(true);
        expect(enzymeWrapper.find('.error-text').text()).toBe('请求的页面资源未找到');
    });
    it('应该会渲染出status为400的Error组件' , () => {
        const { enzymeWrapper , props } = setup2();
        expect(enzymeWrapper.find('div.error-box').hasClass('error-box')).toBe(true);
        expect(enzymeWrapper.find('.error-text').text()).toBe(props.error.statusText);
    })
});

