adding enzyme test

This commit is contained in:
Ken
2019-02-24 14:02:44 -08:00
parent bee197bd72
commit 58721000ac
9 changed files with 503 additions and 42 deletions

View File

@@ -0,0 +1,13 @@
import React from 'react';
import { mount } from 'enzyme';
import { TestMe } from './TestMe';
describe('TestMe Component', () => {
it('should render correctly when hovered', () => {
// TODO:
// 1. mount a <TestMe> Component here
// 2. use enzyme wrapper's find() method to retrieve the #innerMe element
// 3. simulate a hover with "mouseover" event via the simulate() API
// 4. make assertions with expect on the text() of the #innerMe element
});
});

View File

@@ -0,0 +1,37 @@
import React from 'react';
export interface TestMeProps {
name: string;
}
export interface TestMeState {
enabled: boolean;
}
export const TestMe = (props: TestMeProps) => {
return (
<div id="testMe">
<InnerMe name={props.name} />
</div>
);
};
export class InnerMe extends React.Component<TestMeProps, TestMeState> {
state = {
enabled: false
};
onMouseOver = () => {
this.setState({ enabled: true });
};
render() {
return !this.state.enabled ? (
<div onMouseOver={this.onMouseOver} id="innerMe">
Hello {this.props.name}, Hover Over Me
</div>
) : (
<div id="innerMe">Enabled</div>
);
}
}