I'm currently trying to unit test a computed properties.
I have a fileOne.ts file :
export const fileOne = () => {
const fx1 = computed ( () => { ... } );
const fx2 = computed ( () => { ... } );
const fx3 = computed ( () => { ... } );
}
this 'fileOne' is used in a Vue.vue aswell :
<template>
...
</template>
<script lang="ts">
import { fileOne } from './fileOne';
const fileOneState = fileOne( ... );
...
</script>
I want to unit test my computed properties of fileOne. At the moment i have a file named : 'fileOne.spec.ts' with :
describe('testing computed properties', () => {
it('should return the right value', () => {
expect().toBe();
})
});
The problem is : I don't know what I need to import either how to get a instance with my computed properties to test.
I believe this is not clear but if someone understood, i'll be happy to have some helps.
Thanks
Most likely you don't need to test the computed value, but extract the methods you are passing as arguments to computed and test those.
There is no need for unit testing to test the computed versions, but just your own business logic.
One of doing this is to either
fileOne.ts and fileOne.spec.ts orfileOne.ts and import them in fileOne.spec.ts.I would go with option 1 as it clearly marks the fact that you are exporting some custom business logic and the fact that it ends up in a computed method is secondary. You can import that anywhere now.