I have a method called toggleSelect
that adds and removes objects from an array called selectedItems
. This works perfectly live in the browser.
It doesn't seem to work during my unit test. Not clear why because I'm calling it directly from the component and passing it an argument. If I console.log()
the item inside the method, it does display in the log correctly. The method runs, but the array never gets updated to verify that it works.
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 }
})
// toggle method directly on component
wrapper.vm.toggleSelect(items[0])
// verify that the array has been updated
console.log(DataTable.data().selectedItems)
The log shows an empty array just in the test.
DataTable.data().selectedItems
should be wrapper.vm.selectedItems
.
The component instance's data properties are also exposed on wrapper.vm
, so you would access the instance's current data directly by key:
expect(wrapper.vm.selectedItems).toContain(items[0])