mirror of
				https://gitee.com/vant-contrib/vant.git
				synced 2025-10-31 11:32:09 +08:00 
			
		
		
		
	
		
			
				
	
	
		
			75 lines
		
	
	
		
			1.4 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			75 lines
		
	
	
		
			1.4 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
| import Switch from '..';
 | |
| import { mount } from '../../../test/utils';
 | |
| 
 | |
| test('emit event', () => {
 | |
|   const input = jest.fn();
 | |
|   const change = jest.fn();
 | |
|   const wrapper = mount(Switch, {
 | |
|     context: {
 | |
|       on: {
 | |
|         input,
 | |
|         change
 | |
|       }
 | |
|     }
 | |
|   });
 | |
|   wrapper.trigger('click');
 | |
| 
 | |
|   expect(input).toHaveBeenCalledWith(true);
 | |
|   expect(change).toHaveBeenCalledWith(true);
 | |
| });
 | |
| 
 | |
| test('disabled', () => {
 | |
|   const input = jest.fn();
 | |
|   const change = jest.fn();
 | |
|   const wrapper = mount(Switch, {
 | |
|     context: {
 | |
|       on: {
 | |
|         input,
 | |
|         change
 | |
|       }
 | |
|     },
 | |
|     propsData: {
 | |
|       disabled: true
 | |
|     }
 | |
|   });
 | |
|   wrapper.trigger('click');
 | |
| 
 | |
|   expect(input).toHaveBeenCalledTimes(0);
 | |
|   expect(change).toHaveBeenCalledTimes(0);
 | |
| });
 | |
| 
 | |
| test('active-value & inactive-value prop', () => {
 | |
|   const input = jest.fn();
 | |
|   const change = jest.fn();
 | |
|   const wrapper = mount(Switch, {
 | |
|     propsData: {
 | |
|       value: '1',
 | |
|       activeValue: '1',
 | |
|       inactiveValue: '2'
 | |
|     },
 | |
|     context: {
 | |
|       on: {
 | |
|         input,
 | |
|         change
 | |
|       }
 | |
|     }
 | |
|   });
 | |
| 
 | |
|   wrapper.trigger('click');
 | |
| 
 | |
|   expect(input).toHaveBeenCalledWith('2');
 | |
|   expect(change).toHaveBeenCalledWith('2');
 | |
| });
 | |
| 
 | |
| test('inactive-color prop', () => {
 | |
|   const wrapper = mount(Switch, {
 | |
|     propsData: {
 | |
|       value: '2',
 | |
|       inactiveValue: '2',
 | |
|       inactiveColor: 'black'
 | |
|     }
 | |
|   });
 | |
| 
 | |
|   expect(wrapper).toMatchSnapshot();
 | |
| });
 |