adding bonus content for jest

This commit is contained in:
Ken
2019-03-04 11:36:08 -08:00
parent 6a15f0f6b6
commit 547e268bc8
15 changed files with 357 additions and 0 deletions
+11
View File
@@ -0,0 +1,11 @@
import React from 'react';
import { mount } from 'enzyme';
import { TestMe } from './TestMe';
describe('TestMe Component', () => {
it('should have a non-clickable component when the original InnerMe is clicked', () => {
const wrapper = mount(<TestMe name="world" />);
wrapper.find('#innerMe').simulate('click');
expect(wrapper.find('#innerMe').text()).toBe('Clicked');
});
});
+37
View File
@@ -0,0 +1,37 @@
import React from 'react';
export interface TestMeProps {
name: string;
}
export interface TestMeState {
clicked: boolean;
}
export const TestMe = (props: TestMeProps) => {
return (
<div id="testMe">
<InnerMe name={props.name} />
</div>
);
};
export class InnerMe extends React.Component<TestMeProps, TestMeState> {
state = {
clicked: false
};
onClick = () => {
this.setState({ clicked: true });
};
render() {
return !this.state.clicked ? (
<div onClick={this.onClick} id="innerMe">
Hello {this.props.name}, Click Me
</div>
) : (
<div id="innerMe">Clicked</div>
);
}
}
+7
View File
@@ -0,0 +1,7 @@
import React from 'react';
import { mount } from 'enzyme';
describe('index', () => {
it('placeholder', () => {
});
});
+19
View File
@@ -0,0 +1,19 @@
import { multiply } from './multiply';
let counter = 0;
export function getCount() {
return counter;
}
export function increment() {
return ++counter;
}
export function decrement() {
return --counter;
}
export function square(x: number) {
return multiply(x, x);
}
+3
View File
@@ -0,0 +1,3 @@
export function multiply(x: number, y: number) {
return x * y;
}