| 12345678910111213141516171819202122232425262728293031323334353637383940 |
- import { mount, createLocalVue } from "@vue/test-utils"
- import ElementUI from "element-ui"
- import ProductPicker from "@/views/admin/components/ProductPicker.vue"
- jest.mock("@/api/admin", () => ({
- linkedProductList: jest.fn().mockResolvedValue({
- code: 200,
- data: {
- total: 2,
- list: [
- { id: 11, name: "商品A", price: 1000, stock: 10, hasSkus: false, skus: [] },
- { id: 12, name: "商品B", price: 2000, stock: 20, hasSkus: false, skus: [] }
- ]
- }
- })
- }))
- const localVue = createLocalVue()
- localVue.use(ElementUI)
- const flush = () => new Promise(r => setTimeout(r, 60))
- describe("ProductPicker 单选(关联商品)模式", () => {
- it("点击单选框后该radio应显示勾选态(is-checked)", async () => {
- const wrapper = mount(ProductPicker, {
- localVue,
- propsData: { multiple: false, crossCategory: false, selected: null },
- attachTo: document.body
- })
- wrapper.vm.open()
- await flush()
- const radios = wrapper.findAll(".el-radio")
- expect(radios.length).toBe(2)
- const radio = radios.at(0)
- await radio.trigger("click")
- await wrapper.vm.$nextTick()
- expect(radio.classes()).toContain("is-checked")
- wrapper.destroy()
- })
- })
|