One of my methods is called toggleSelect
which adds and removes items from an array named selectedItems
. This method functions perfectly when I test it live in the browser. However, when running unit tests, it does not seem to work as expected. Despite calling it directly from the component and passing it an argument, the array does not get updated during testing. Even though I use console.log()
to display the item correctly inside the method, the array remains unchanged.
let items = [{
"ID": "12345",
"Name": "Real Person",
"Description": "How a real person ought to be described",
"Date": "2015-04-12T04:24:49-07:00",
"Amount": 120.23
}]
const wrapper = shallowMount(DataTable, {
propsData: { items }
})
// Using toggleSelect method directly on the component
wrapper.vm.toggleSelect(items[0])
// Checking if the array has been updated
console.log(DataTable.data().selectedItems)
When conducting the test, the log displays an empty array.