I am trying to write my first Vue unit test, but I am unable to get the data property to change after function runs It runs fine on the UI front
I've multiple data objects
data() {
return {
collections: [],
inlineVisibility: false,
inlineTitle: '',
inlineSubtitle: '',
inlineKind: '',
loading: false,
}
},
The function is
async loadcsv(element=null, testCase = null) {
const reader = new FileReader()
let file = new Blob([workingCSV])
this.toggleLoading() //This works, this turns the loading to true but nothing after this works in test
reader.onload = async (e) => {
try {
collections.push(e)
} catch (err) {
this.inlineTitle = "Error"
}
}
reader.readAsText(file)
},
This is the test I wrote till now
describe('ModalAddCollectionCSV', () => {
it('Test load csv function', async () => {
const localVue = createLocalVue()
const wrapper = mount(ModalAddCollectionCSV, {
localVue,
propsData: {
visible: true,
},
})
const data = wrapper.vm.loadcsv() //data is always {} and does not even update the data property
expect(wrapper.vm.$data.collections).toContain([Array])
})
})
I've even tried shallow mount
I am using jest, and it seems there's an issue with the file reader