odavid / typeorm-transactional-cls-hooked

A Transactional Method Decorator for typeorm that uses cls-hooked to handle and propagate transactions between different repositories and service methods. Inpired by Spring Trasnactional Annotation and Sequelize CLS
MIT License
522 stars 86 forks source link

How to test that method uses Transactional decorator? #86

Closed boy51 closed 3 years ago

boy51 commented 3 years ago

Hi,

thanks for this awesome lib!

is there a way to verify in jest that a method is decorated with @Transactional()?

@Transactional()
something() {
 // ...
}
it("runs in a transaction", () => {
 // ???
})

Any help is much appreciated :-)

odavid commented 3 years ago

Thanks @boy51... I am not sure about it...

If mocking is what you try to achieve, then you can mock it like mentioned here: https://github.com/odavid/typeorm-transactional-cls-hooked#unit-test-mocking

If you are trying to get decorator metadata, I believe reflect-metadata is the place to search for answers (Haven't used it yet, so not an expert ;)