0
我正在寫一個簡單的測試反應組件使用酶來創建一個淺的克隆,這是不應該的時候失敗。我想看到的兩件事是,如果它變好,並且它有一個道具。這兩個都失敗了。在這裏,我測試的組件和我的規格:使用酶的簡單茉莉花測試失敗。
我的組件:
import * as React from 'react';
export default class PortfolioItem extends React.Component<any, any> {
render() {
// Deconstructing the items obj into these consts
const {
ID,
abbreviation,
active,
managementCompany,
name,
targetOperatingReserve
} = this.props.item;
return (
<tr className='.item'>
<td className='id' >{ID}</td>
<td className='abv' >{abbreviation}</td>
<td className='active' >{active}</td>
<td className='manComp' >{managementCompany}</td>
<td className='name' >{name}</td>
<td className='tor' >{targetOperatingReserve}</td>
</tr>
);
}
}
我的規格:
import * as React from 'react';
import { shallow } from 'enzyme';
import PortfolioItem from '../../src/js/components/PortfolioItem';
const createShallowPortfolioItem =() => {
const props = {
item: {
ID: 1234567,
abbreviation: 'rit',
active: true,
managementCompany: false,
name: 'Jorge Joestar',
targetOperatingReserve: 0.0
}
};
return shallow(<PortfolioItem {...props} />);
};
describe('PortfolioItem',() => {
it('it contains the class name item',() => {
const portItem = createShallowPortfolioItem();
expect(portItem.is('.item')).toBeTruthy();
});
it('renders the item name',() => {
const item = createShallowPortfolioItem();
expect(item.find('.name').text()).toEqual('Jorge Joestar');
});
});