vendredi 5 octobre 2018

Testing React components passed through by asp.net razor

I was wondering if this is possible and/or is good way of testing my views? As a starting point I am trying to make this basic test pass, but the 'App.js' parent is what is passed through using Razor, which doesn't exist...

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 - My attempted test

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);
});

Aucun commentaire:

Enregistrer un commentaire