I try to test my component that has a function to add an item to the array and each of those items has UUID property but I get this error when I try to run the unit test for that.
TypeError: Cannot read property 'v1' of undefined
const basicDataItem = {
> 380 | id: this.$uuid.v1()
How can I test the code that uses UUID like in this case?
edit: this is the function that I want to test
addDataItem(key) {
const basicDataItem = {
id: this.$uuid.v1(),
units: '',
price: '',
label: '',
};
this.editableData[key].push(basicDataItem);
}
Here is a unit test solution for your case:
index.js:index.spec.js:Unit test result with coverage report:
Source code: https://github.com/mrdulin/jest-codelab/tree/master/src/stackoverflow/58710736