SyntaxError:将prop类型传递给测试用例时

时间:2016-03-16 00:59:07

标签: javascript jquery html reactjs mocha

  • 我正在尝试为我的jsx文件编写测试用例......
  • 我从另一个jsx文件中获取了示例测试用例......
  • 我面临语法错误....传递proptypes ....
  • 我认为因为这打破了我的测试案例......
  • 你能告诉我如何解决它..
  • 在下方提供我的代码......

清除 https://gist.github.com/js08/d590e78e8923e68b191a

下面的代码

SyntaxError:C:/codebase/sports/test/sports-tests.js:意外的令牌(20:73)   18 |   19 |它('应正确渲染',()=> { 的> 20 | shallowRenderer.render();      | ^   21 | / * let renderedElement = shallowRenderer.getRenderOutput();   22 |

test case
import {expect} from 'chai';
import React from 'react';
import TestUtils from 'react-addons-test-utils';
import sportsPageDefault from '../src/sports-Page-Default';
import initializeJsDom from './test-utils/dom.js';
import {getGridLayoutClasses} from 'sports-css-grids';
//import _difference from 'lodash/array/difference';


describe('shallow renderer tests for sports-Page-Default ', function() {
    let shallowRenderer = TestUtils.createRenderer();
    console.log("shallowRenderer" + JSON.stringify(shallowRenderer));


    it('should render correctly', () => {
        shallowRenderer.render(<sportsPageDefault headerClass='8887' layout= {id: 100, text: 'hello world'} sidebar= {id: 100, text: 'hello world'} title="Demo" />);
        let renderedElement = shallowRenderer.getRenderOutput();
        console.log(renderedElement);

       /* let actualTitleEl = renderedElement.props.children[0].props.children[0];
        let expectedTitleEl = <h1 className="transactionalPageHeader-appName font-serif">Demo</h1>;
        expect(actualTitleEl).to.deep.equal(expectedTitleEl);*/
    });



});

actual code

import './css/sports-bottom-layout.css';
import './css/sports-Page.css';
import './css/sports-leftCornerLayout.css';

import React from 'react';
import PageHeader from './components/page-header/page-header';
import MainContent from './components/main-content';
import sports-bottom-layout from './components/sports-bottom-layout/sports-bottom-layout';
import {getPanelLayoutState} from './util/PageLayout';
import {getGridLayoutClasses} from 'sports-css-grids/lib/js/gridLayout';
import PagePureRenderMixin from './util/PagePureRenderMixin';
import {connect} from 'react-redux';
import {setHeaderPanelState, setRightPanelState} from './redux/layout/layout-actions';

console.log("inside");
let customMixin = PagePureRenderMixin({
    state: {
        mainPanelGridClassList: function(classArray) {
            return classArray.length;
            console.log("classArray.length" + classArray.length);
        }
    }
});

let PT = React.PropTypes;

let sportsPageDefault = React.createClass({


    propTypes: {
        headerClass: React.PropTypes.string,
        layout: PT.object.isRequired,
        sports-leftCornerLayout: PT.oneOfType([
            PT.func,
            PT.object
        ]),
        title: PT.string.isRequired
    },


    //cpomponent m,ount code

});

function sportsShallow(itemA, itemB) {
    for (let i in itemA) {
        if (itemA[i] !== itemB[i]) {
            return false;
        }
    }
    return true;
}

export default connect(state => ({
    layout: state.Page.layout
}))(sportsPageDefault);

**but another file it works fine, for example**
 propTypes: {
        footer: React.PropTypes.bool,
        onAppExit: React.PropTypes.func.isRequired,
        title: React.PropTypes.string.isRequired
    },
        let component = TestUtils.renderIntoDocument(<sports title="Demo" onAppExit={onAppExit}/>);

0 个答案:

没有答案