Skip to content

Commit

Permalink
fix: test
Browse files Browse the repository at this point in the history
  • Loading branch information
chungchiehlun committed Feb 4, 2021
1 parent 74dd097 commit 6fa8116
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 18 deletions.
19 changes: 7 additions & 12 deletions src/__tests__/__snapshots__/index.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ exports[`snapshot - default 1`] = `
<section
className="CTE--wrapper"
data-value="foo"
onClick={[Function]}
>
<span
className="CTE--text"
onClick={[Function]}
>
foo
</span>
Expand All @@ -18,17 +18,12 @@ exports[`snapshot - onEdit 1`] = `
<section
className="CTE--wrapper"
data-value="bar"
onClick={[Function]}
>
<input
autoFocus={true}
className="CTE--input"
onBlur={[Function]}
onChange={[Function]}
onKeyPress={[Function]}
size="1"
type="text"
value="bar"
/>
<span
className="CTE--text"
onClick={[Function]}
>
bar
</span>
</section>
`;
12 changes: 6 additions & 6 deletions src/__tests__/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,23 +30,23 @@ test("enter editing mode when clicking CTE", () => {
const wrapper = shallow(
<ClickToEdit initialValue="HELLO" endEditing={jest.fn()} />
);
wrapper.simulate("click");
wrapper.find("span").simulate("click");
expect(wrapper.find("input")).toHaveLength(1);
});

test("enter editing mode and change value", () => {
const wrapper = shallow(
<ClickToEdit initialValue="HELLO" endEditing={jest.fn()} />
);
wrapper.simulate("click");
wrapper.find("span").simulate("click");
wrapper.find("input").simulate("change", { target: { value: "WORLD" } });
expect(wrapper.find("input").prop("value")).toBe("WORLD");
});

test("invoke endEditing function and leave editing mode after pressing the enter key", () => {
const mock = jest.fn();
const wrapper = mount(<ClickToEdit initialValue="HELLO" endEditing={mock} />);
wrapper.simulate("click");
wrapper.find("span").simulate("click");
const inputWrapper = wrapper.find("input");
inputWrapper.simulate("keypress", {
keyCode: 13
Expand All @@ -58,7 +58,7 @@ test("invoke endEditing function and leave editing mode after pressing the enter
test("invoke endEditing function and leave editing mode after blurring the input", () => {
const mock = jest.fn();
const wrapper = mount(<ClickToEdit initialValue="HELLO" endEditing={mock} />);
wrapper.simulate("click");
wrapper.find("span").simulate("click");
const inputWrapper = wrapper.find("input");
inputWrapper.simulate("blur");
expect(mock).toHaveBeenCalledTimes(1);
Expand All @@ -68,7 +68,7 @@ test("invoke endEditing function and leave editing mode after blurring the input
test("stay on editing mode if press all keys except Enter key", () => {
const mock = jest.fn();
const wrapper = mount(<ClickToEdit initialValue="HELLO" endEditing={mock} />);
wrapper.simulate("click");
wrapper.find("span").simulate("click");
const inputWrapper = wrapper.find("input");
inputWrapper.simulate("keypress", {
keyCode: 1
Expand All @@ -90,6 +90,6 @@ test("pass class props to customize component style", () => {
expect(wrapper.hasClass("wrapperClass")).toBeTruthy();
expect(wrapper.find("span.textClass")).toHaveLength(1);

wrapper.simulate("click");
wrapper.find("span").simulate("click");
expect(wrapper.find("input.inputClass")).toHaveLength(1);
});

0 comments on commit 6fa8116

Please sign in to comment.