index.spec.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. import { mount } from '../../../test/utils';
  2. import Actionsheet from '..';
  3. test('callback events', () => {
  4. const callback = jest.fn();
  5. const onInput = jest.fn();
  6. const onCancel = jest.fn();
  7. const onSelect = jest.fn();
  8. const actions = [
  9. { name: 'Option', callback },
  10. { name: 'Option', disabled: true }
  11. ];
  12. const wrapper = mount(Actionsheet, {
  13. propsData: {
  14. value: true,
  15. actions,
  16. cancelText: 'Cancel'
  17. },
  18. context: {
  19. on: {
  20. input: onInput,
  21. cancel: onCancel,
  22. select: onSelect
  23. }
  24. }
  25. });
  26. const options = wrapper.findAll('.van-actionsheet__item');
  27. options.at(0).trigger('click');
  28. options.at(1).trigger('click');
  29. wrapper.find('.van-actionsheet__cancel').trigger('click');
  30. expect(callback).toHaveBeenCalled();
  31. expect(onCancel).toHaveBeenCalled();
  32. expect(onInput).toHaveBeenCalledWith(false);
  33. expect(onSelect).toHaveBeenCalledWith(actions[0], 0);
  34. expect(wrapper).toMatchSnapshot();
  35. });
  36. test('disable lazy-render', () => {
  37. const wrapper = mount(Actionsheet, {
  38. propsData: {
  39. lazyRender: false,
  40. actions: [
  41. { name: 'Option' },
  42. { name: 'Option' }
  43. ],
  44. cancelText: 'Cancel'
  45. }
  46. });
  47. expect(wrapper).toMatchSnapshot();
  48. });
  49. test('get container', () => {
  50. const wrapper = mount(Actionsheet, {
  51. propsData: {
  52. value: true,
  53. getContainer: 'body'
  54. }
  55. });
  56. expect(wrapper.vm.$el.parentNode).toEqual(document.body);
  57. });