api-client/components/smart/__tests__/Toggle.spec.js

53 lines
1.4 KiB
JavaScript
Raw Normal View History

import { mount } from "@vue/test-utils"
2021-05-18 09:27:29 +00:00
import pwToggle from "../Toggle"
const factory = (props, slot) =>
mount(pwToggle, {
propsData: props,
slots: {
default: slot,
},
})
describe("pwToggle", () => {
test("mounts properly", () => {
const wrapper = factory({ on: true }, "test")
expect(wrapper).toBeTruthy()
})
test("mounts even without the on prop", () => {
const wrapper = factory({}, "test")
expect(wrapper).toBeTruthy()
})
test("state is set correctly through the prop", () => {
const wrapper1 = factory({ on: true }, "test")
expect(wrapper1.vm.$refs.toggle.classList.contains("on")).toEqual(true)
const wrapper2 = factory({ on: false }, "test")
expect(wrapper2.vm.$refs.toggle.classList.contains("on")).toEqual(false)
})
test("caption label is rendered", () => {
const wrapper = factory({ on: true }, "<span id='testcaption'></span>")
expect(wrapper.find("#testcaption").exists()).toEqual(true)
})
2021-07-08 08:30:18 +00:00
// test("clicking the button toggles the state", async () => {
// const wrapper = factory({ on: true }, "test")
2021-07-08 08:30:18 +00:00
// wrapper.vm.toggle()
// await wrapper.vm.$nextTick()
2021-07-08 08:30:18 +00:00
// expect(wrapper.vm.$refs.toggle.classList.contains("on")).toEqual(false)
2021-07-08 08:30:18 +00:00
// wrapper.vm.toggle()
// await wrapper.vm.$nextTick()
2021-07-08 08:30:18 +00:00
// expect(wrapper.vm.$refs.toggle.classList.contains("on")).toEqual(true)
// })
})