Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test #1

Merged
merged 5 commits into from
Jul 19, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions App.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ const App = () => (
<div className={styles.container}>
<MDSearchBox
onChange={(text) => { console.log(`changed to ${text}`); }}
width={300}
height={42}
/>
</div>
);
Expand Down
4 changes: 2 additions & 2 deletions lib/MDSearchBox.css
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
-ms-flex-align: center;
align-items: center;

width: 300px;
/*width: 300px;*/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

如果default props里面有width,那么这里是可以把width删除的。如果你把default props里面的width删了,那么这里就不能删。我觉得前者比较合理和直观

border: 1px solid #ccc;
background-color: white;
box-sizing: border-box;
}
/*box-sizing: border-box;*/
:local .container .searchbox {
margin: 10px 10px;
display: -webkit-box;
Expand Down
2 changes: 1 addition & 1 deletion src/MDSearchBox.css
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
justify-content: space-between;
align-items: center;

width: 300px;
/*width: 300px;*/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same. You can remove it given that the with in defaulProps are still there

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same. You can remove it given that the width in defaulProps are still there

border: 1px solid #ccc;
background-color: white;
box-sizing: border-box;
Expand Down
69 changes: 68 additions & 1 deletion test/MDSearchBox.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,74 @@ import MDSearchBox from 'src/MDSearchBox';
expect.extend(expectJSX);

describe('MDSearchBox', () => {
it('should work', () => {
describe('default case', () => {
let wrapper;

before(() => {
wrapper = shallow(<MDSearchBox />);
});

it('should have no input value', () => {
const input = wrapper.find('input');
expect(input.props().value).toBe(undefined);
});

});

describe('with text', () => {
let wrapper;

before(() => {
wrapper = shallow(
<MDSearchBox
text="haha"
/>
);
});

it('should have corresponding text', () => {
const input = wrapper.find('input');
expect(input.props().value).toBe('haha');

});
})

// describe('with onChange method', () => {
// let wrapper;
//
// before(() => {
// wrapper = shallow(
// <MDSearchBox
// onChange={() => {
// return 'xixi';
// }}
// />
// );
// });
//
// it('should trigger the onChange', () => {
// const input = wrapper.find('input');
// // const event = { preventDefault: () => 'a' }
// input.simulate('change');
// expect(input.props().onChange()).toBe('xixi');
// })
// })

describe('with size changed', () => {
let wrapper;

before(() => {
wrapper = shallow(
<MDSearchBox
width={500}
height={300}
/> );
});

it('size should change', () => {
expect(wrapper.props().style).toEqual({width:500, height:300});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

better split that assertion into two assertions.
expect(wrapper.props().style.width).toEqual(500);
expect(wrapper.props().style.height).toEqual(300);

or you can use include
expect(wrapper.props().style).to.include({ width:500, height:300 })


});
})

});