如何使用jest.fn()模拟属性

时间:2019-11-06 17:19:22

标签: vue.js vuejs2 jestjs

我有以下代码:

companion object {
        val COMPARATOR = object : DiffUtil.ItemCallback<Reservation>() {
            override fun areContentsTheSame(oldItem: Reservation, newItem: Reservation): Boolean =
                oldItem == newItem

            override fun areItemsTheSame(oldItem: Reservation, newItem: Reservation): Boolean =
                oldItem.id == newItem.id
        }
    }

我需要像这样将模拟传递给shallowMount:

this.$vs.loading()
....
this.$vs.loading.close()

但是我该如何嘲笑const vs = { loading: jest.fn() } mocks: { $vs: vs } loading

我使用close来模拟loading: jest.fn()。如何在loading()属性中模拟close()

1 个答案:

答案 0 :(得分:0)

您可以将模拟属性附加到模拟函数本身:

const vs = {
  loading: jest.fn()
}
vs.loading.close = jest.fn()