index.spec.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import Radio from '..';
  2. import RadioGroup from '../../radio-group';
  3. import { mount } from '../../../test/utils';
  4. test('radio-group change', () => {
  5. const wrapper = mount({
  6. template: `
  7. <radio-group v-model="result" @change="$emit('change', $event)">
  8. <radio
  9. v-for="item in list"
  10. :key="item"
  11. :name="item"
  12. :disabled="item === 'd'"
  13. >
  14. label
  15. </radio>
  16. </radio-group>
  17. `,
  18. components: {
  19. Radio,
  20. RadioGroup
  21. },
  22. data() {
  23. return {
  24. result: 'a',
  25. list: ['a', 'b', 'c', 'd']
  26. };
  27. }
  28. });
  29. const icons = wrapper.findAll('.van-radio__icon');
  30. const labels = wrapper.findAll('.van-radio__label');
  31. icons.at(2).trigger('click');
  32. expect(wrapper.vm.result).toEqual('c');
  33. expect(wrapper.emitted('change')[0][0]).toEqual('c');
  34. labels.at(1).trigger('click');
  35. expect(wrapper.vm.result).toEqual('b');
  36. expect(wrapper.emitted('change')[1][0]).toEqual('b');
  37. icons.at(3).trigger('click');
  38. labels.at(3).trigger('click');
  39. expect(wrapper.vm.result).toEqual('b');
  40. });