Skip to content

Commit

Permalink
add test for switch, ref #1274 (#1513)
Browse files Browse the repository at this point in the history
* add test for switch, ref #1274

* add issue url

* fix: test
  • Loading branch information
silentcloud authored and paranoidjk committed Jun 30, 2017
1 parent e54cdc1 commit 3f2fab7
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -593,6 +593,7 @@ exports[`renders ./components/list/demo/form.md correctly 1`] = `
class="am-switch-checkbox"
name=""
type="checkbox"
value="on"
/>
<div
class="checkbox"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ exports[`renders ./components/switch/demo/basic.md correctly 1`] = `
class="am-switch-checkbox"
name=""
type="checkbox"
value="on"
/>
<div
class="checkbox"
Expand Down Expand Up @@ -67,6 +68,7 @@ exports[`renders ./components/switch/demo/basic.md correctly 1`] = `
class="am-switch-checkbox"
name=""
type="checkbox"
value="off"
/>
<div
class="checkbox"
Expand Down Expand Up @@ -101,6 +103,7 @@ exports[`renders ./components/switch/demo/basic.md correctly 1`] = `
disabled=""
name=""
type="checkbox"
value="off"
/>
<div
class="checkbox checkbox-disabled"
Expand Down Expand Up @@ -136,6 +139,7 @@ exports[`renders ./components/switch/demo/basic.md correctly 1`] = `
disabled=""
name=""
type="checkbox"
value="on"
/>
<div
class="checkbox checkbox-disabled"
Expand Down Expand Up @@ -169,6 +173,7 @@ exports[`renders ./components/switch/demo/basic.md correctly 1`] = `
class="am-switch-checkbox"
name=""
type="checkbox"
value="off"
/>
<div
class="checkbox"
Expand Down Expand Up @@ -203,6 +208,7 @@ exports[`renders ./components/switch/demo/basic.md correctly 1`] = `
class="am-switch-checkbox"
name=""
type="checkbox"
value="on"
/>
<div
class="checkbox"
Expand Down
21 changes: 21 additions & 0 deletions components/switch/__tests__/__snapshots__/index.test.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Switch renders correctly 1`] = `
<RCTSwitch
disabled={false}
onChange={[Function]}
onResponderTerminationRequest={[Function]}
onStartShouldSetResponder={[Function]}
onValueChange={[Function]}
style={
Array [
Object {
"height": 31,
"width": 51,
},
undefined,
]
}
value={true}
/>
`;
18 changes: 18 additions & 0 deletions components/switch/__tests__/__snapshots__/index.test.web.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`SegmentedControl renders correctly 1`] = `
<label
class="am-switch"
>
<input
checked=""
class="am-switch-checkbox"
name=""
type="checkbox"
value="on"
/>
<div
class="checkbox"
/>
</label>
`;
10 changes: 10 additions & 0 deletions components/switch/__tests__/index.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import React from 'react';
import renderer from 'react-test-renderer';
import Switch from '../index';

describe('Switch', () => {
it('renders correctly', () => {
const tree = renderer.create(<Switch checked />).toJSON();
expect(tree).toMatchSnapshot();
});
});
18 changes: 18 additions & 0 deletions components/switch/__tests__/index.test.web.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import React from 'react';
import { render, shallow } from 'enzyme';
import { renderToJson } from 'enzyme-to-json';
import Switch from '../index.web';

describe('SegmentedControl', () => {
it('renders correctly', () => {
const wrapper = render(<Switch checked />);
expect(renderToJson(wrapper)).toMatchSnapshot();
});

it('check api', () => {
const onChange = jest.fn();
const wrapper = shallow(<Switch checked onChange={onChange} />);
wrapper.find('input').simulate('change', { target: { checked: false } });
expect(onChange).toHaveBeenCalledWith(false);
});
});
1 change: 1 addition & 0 deletions components/switch/index.web.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ export default class Switch extends React.Component<SwitchProps, any> {
disabled={disabled}
checked={checked}
onChange={this.onChange}
value={checked ? 'on' : 'off'}
{...(!disabled ? { onClick: this.onClick } : {})}
{...globalProps}
/>
Expand Down

0 comments on commit 3f2fab7

Please sign in to comment.