Toggle.spec.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. import { mount } from "@vue/test-utils"
  2. import pwToggle from "../Toggle"
  3. const factory = (props, slot) =>
  4. mount(pwToggle, {
  5. propsData: props,
  6. slots: {
  7. default: slot,
  8. },
  9. })
  10. describe("pwToggle", () => {
  11. test("mounts properly", () => {
  12. const wrapper = factory({ on: true }, "test")
  13. expect(wrapper).toBeTruthy()
  14. })
  15. test("mounts even without the on prop", () => {
  16. const wrapper = factory({}, "test")
  17. expect(wrapper).toBeTruthy()
  18. })
  19. test("state is set correctly through the prop", () => {
  20. const wrapper1 = factory({ on: true }, "test")
  21. expect(wrapper1.vm.$refs.toggle.classList.contains("on")).toEqual(true)
  22. const wrapper2 = factory({ on: false }, "test")
  23. expect(wrapper2.vm.$refs.toggle.classList.contains("on")).toEqual(false)
  24. })
  25. test("caption label is rendered", () => {
  26. const wrapper = factory({ on: true }, "<span id='testcaption'></span>")
  27. expect(wrapper.find("#testcaption").exists()).toEqual(true)
  28. })
  29. // test("clicking the button toggles the state", async () => {
  30. // const wrapper = factory({ on: true }, "test")
  31. // wrapper.vm.toggle()
  32. // await wrapper.vm.$nextTick()
  33. // expect(wrapper.vm.$refs.toggle.classList.contains("on")).toEqual(false)
  34. // wrapper.vm.toggle()
  35. // await wrapper.vm.$nextTick()
  36. // expect(wrapper.vm.$refs.toggle.classList.contains("on")).toEqual(true)
  37. // })
  38. })