测试由asp.net剃须刀通过的React组件

时间:2018-10-05 13:54:48

标签: reactjs testing razor jestjs enzyme

我想知道这是否可能和/或测试我的观点的好方法?首先,我尝试通过此基本测试,但是'App.js'父级是使用Razor传递的,它不存在...

somePage.cshtml

<div>
    <h1>Some Page</h1>

    @Html.React("App.Components.Faqs", new
    {
        somePage  = Model
    })
</div>

somePage.js

import React, { Component } from 'react';

import ComponentOne from './component_one';
import ComponentTwo from './component_two';

const somePage = () => {    
    render() {
        return (
            <div>
                <ComponentOne/>
                <ComponentTwo/>
            </div>
        );
    }
}

somePage.test.js-我尝试的测试

import React from 'react';
import { shallow } from 'enzyme';
import App from '../App';
import ComponentOne from 'components/component_one';
import ComponentTwo from 'components/component_two';

let App;

beforeEach(() => {
    component = shallow(<App />);
});

it('has one component of ComponentOne', () => {
    expect(component.find(ComponentOne).length).toEqual(1);
});

0 个答案:

没有答案