茉莉花 - 窥探第三方组件

时间:2018-06-07 08:15:18

标签: javascript jasmine

我正在使用Vue Js来开发Web组件。为了确保图像在ie11中看起来正确,我安装了一个名为object-fit-images的npm模块。

我的组件挂载方法我调用了objectFitImages()

import objectFitImages from 'object-fit-images'
export default {
  name: 'my-component'
  methods: {
    mounted () {
      objectFitImages()
    }
  }
I want to test that this method is called.

So, I can't use spyOn because it's not an object with methods so I don't know what parameter to provide for the method ('default' doesn't work as it doesn't exist).

Also in my test, if I try to assign a spy directly to it using:

objectFitImages = jasmine.createSpy() 

I get the message that Module build failed because objectFitImages in read only. 

Also, I can't just create a global variable like this (without importing it) because strict mode prevents global variables being created.

Any ideas how to mock this out and test that my mounted method is calling objectFitImages????

Many thanks

0 个答案:

没有答案