vModel.spec.ts 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import path from 'node:path'
  2. import { setupPuppeteer } from './e2eUtils'
  3. const { page, click, isChecked } = setupPuppeteer()
  4. import { nextTick } from 'vue'
  5. beforeEach(async () => {
  6. await page().addScriptTag({
  7. path: path.resolve(__dirname, '../../dist/vue.global.js'),
  8. })
  9. await page().setContent(`<div id="app"></div>`)
  10. })
  11. // #12144
  12. test('checkbox click with v-model', async () => {
  13. await page().evaluate(() => {
  14. const { createApp } = (window as any).Vue
  15. createApp({
  16. template: `
  17. <label>
  18. <input
  19. id="first"
  20. type="checkbox"
  21. v-model="first"/>
  22. First
  23. </label>
  24. <br>
  25. <label>
  26. <input
  27. id="second"
  28. type="checkbox"
  29. v-model="second"
  30. @click="secondClick"/>
  31. Second
  32. </label>
  33. `,
  34. data() {
  35. return {
  36. first: true,
  37. second: false,
  38. }
  39. },
  40. methods: {
  41. secondClick(this: any) {
  42. this.first = false
  43. },
  44. },
  45. }).mount('#app')
  46. })
  47. expect(await isChecked('#first')).toBe(true)
  48. expect(await isChecked('#second')).toBe(false)
  49. await click('#second')
  50. await nextTick()
  51. expect(await isChecked('#first')).toBe(false)
  52. expect(await isChecked('#second')).toBe(true)
  53. })