-
Hi there. I have been trying to use pinia-orm in tests running in vitest, but am facing some problems. I used to be able to just use const fakeData = new MyModel({
id: 999
name: 'Some name'
}) in my jest tests using vuex-orm to instantiate models with random data, but somehow in pinia-orm, this returns a model that is undefined. Or at least, it seems to return the type, but it's emtpy? Here is some output of my debug console when inspectig the model object: I also found https://pinia-orm.codedredd.de/api/repository/make that says the repository make function is pretty much the alternative to const pinia = creatTestingPinia()
const repo = useRepo(Organization, pinia)
const randomData = repo.make({...})
// randomdata has type Organization but when trying to access its attributes, it throws the error that and attribute of an undefined object is trying to be read. Can anyone help me to figure this out? Has anyone else successfully used pinia-orm in tests? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
@dschreij Just look at my tests 😉
The big difference betweeen vuex-orm and pinia-orm is, that the complete logic doesn't exist anymore in the store. |
Beta Was this translation helpful? Give feedback.
@dschreij
yes you can do that. you can just fill the models with the data and how it is set, is defined by the options. Look for example at some of the model unit test: https://github.com/CodeDredd/pinia-orm/blob/master/packages/pinia-orm/tests/unit/model/Model.spec.ts
Maybe i write some helper to mock
useRepo
with return values. I think this will also make testing way easier so that you dont need the store at all.in your case the best way is to set the models by
new Model({...fields}, { operation: 'get' })