|
| 1 | +import { describeWithShallowAndMount, vueVersion, itDoNotRunIf } from '~resources/utils' |
| 2 | +import ComponentWithScopedSlots from '~resources/components/component-with-scoped-slots.vue' |
| 3 | + |
| 4 | +describeWithShallowAndMount('scopedSlots', (mountingMethod) => { |
| 5 | + let _window |
| 6 | + |
| 7 | + beforeEach(() => { |
| 8 | + _window = window |
| 9 | + }) |
| 10 | + |
| 11 | + afterEach(() => { |
| 12 | + if (!window.navigator.userAgent.match(/Chrome/i)) { |
| 13 | + window = _window // eslint-disable-line no-native-reassign |
| 14 | + } |
| 15 | + }) |
| 16 | + |
| 17 | + itDoNotRunIf(vueVersion < 2.5, |
| 18 | + 'mounts component scoped slots', () => { |
| 19 | + const wrapper = mountingMethod(ComponentWithScopedSlots, { |
| 20 | + slots: { default: '<span>123</span>' }, |
| 21 | + scopedSlots: { |
| 22 | + 'foo': '<p slot-scope="foo">{{foo.index}},{{foo.text}}</p>', |
| 23 | + 'bar': '<p slot-scope="bar">{{bar.text}},{{bar.index}}</p>' |
| 24 | + } |
| 25 | + }) |
| 26 | + expect(wrapper.find('#slots').html()).to.equal('<div id="slots"><span>123</span></div>') |
| 27 | + expect(wrapper.find('#foo').html()).to.equal('<div id="foo"><p>0,a1</p><p>1,a2</p><p>2,a3</p></div>') |
| 28 | + expect(wrapper.find('#bar').html()).to.equal('<div id="bar"><p>A1,0</p><p>A2,1</p><p>A3,2</p></div>') |
| 29 | + wrapper.vm.foo = [{ text: 'b1' }, { text: 'b2' }, { text: 'b3' }] |
| 30 | + wrapper.vm.bar = [{ text: 'B1' }, { text: 'B2' }, { text: 'B3' }] |
| 31 | + expect(wrapper.find('#foo').html()).to.equal('<div id="foo"><p>0,b1</p><p>1,b2</p><p>2,b3</p></div>') |
| 32 | + expect(wrapper.find('#bar').html()).to.equal('<div id="bar"><p>B1,0</p><p>B2,1</p><p>B3,2</p></div>') |
| 33 | + } |
| 34 | + ) |
| 35 | + |
| 36 | + itDoNotRunIf(vueVersion < 2.5, |
| 37 | + 'throws exception when it is seted to a template tag at top', () => { |
| 38 | + const fn = () => { |
| 39 | + mountingMethod(ComponentWithScopedSlots, { |
| 40 | + scopedSlots: { |
| 41 | + 'foo': '<template></template>' |
| 42 | + } |
| 43 | + }) |
| 44 | + } |
| 45 | + const message = '[vue-test-utils]: the scopedSlots option does not support a template tag as the root element.' |
| 46 | + expect(fn).to.throw().with.property('message', message) |
| 47 | + } |
| 48 | + ) |
| 49 | + |
| 50 | + itDoNotRunIf(vueVersion >= 2.5, |
| 51 | + 'throws exception when vue version < 2.5', () => { |
| 52 | + const fn = () => { |
| 53 | + mountingMethod(ComponentWithScopedSlots, { |
| 54 | + scopedSlots: { |
| 55 | + 'foo': '<p slot-scope="foo">{{foo.index}},{{foo.text}}</p>' |
| 56 | + } |
| 57 | + }) |
| 58 | + } |
| 59 | + const message = '[vue-test-utils]: the scopedSlots option is only supported in vue@2.5+.' |
| 60 | + expect(fn).to.throw().with.property('message', message) |
| 61 | + } |
| 62 | + ) |
| 63 | + |
| 64 | + itDoNotRunIf(vueVersion < 2.5, |
| 65 | + 'throws exception when using PhantomJS', () => { |
| 66 | + if (window.navigator.userAgent.match(/Chrome/i)) { |
| 67 | + return |
| 68 | + } |
| 69 | + window = { navigator: { userAgent: 'PhantomJS' }} // eslint-disable-line no-native-reassign |
| 70 | + const fn = () => { |
| 71 | + mountingMethod(ComponentWithScopedSlots, { |
| 72 | + scopedSlots: { |
| 73 | + 'foo': '<p slot-scope="foo">{{foo.index}},{{foo.text}}</p>' |
| 74 | + } |
| 75 | + }) |
| 76 | + } |
| 77 | + const message = '[vue-test-utils]: the scopedSlots option does not support PhantomJS. Please use Puppeteer, or pass a component.' |
| 78 | + expect(fn).to.throw().with.property('message', message) |
| 79 | + } |
| 80 | + ) |
| 81 | +}) |
0 commit comments