group.each.setup
and group.each.teardown
not working
#4609
-
Code and setup I am trying to delete all from db and migrate after each test in test group to have clean db between tests. I am following this https://docs.adonisjs.com/guides/testing/database#truncate-tables and this is my code(just to showcase the problem)
Problem I am expecting I have tried a few different ways:
When running
When running
When running
When running
When running
When running
When running
When running I've also tried with both I haven package.json
|
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 3 replies
-
Hey @backspacerhino! 👋🏻 The code What you are looking for is global transaction or truncating the table between each test. test.group('User', (group) => {
group.each.setup(() => testUtils.db().withGlobalTransaction())
}) test.group('User', (group) => {
group.each.setup(() => testUtils.db().truncate())
}) |
Beta Was this translation helpful? Give feedback.
-
I've found the solution.
If you do However it does not work without @RomainLanz this does not seem like how it should work. If you point me to the right direction I can check the source code for this and check why it is behaving like this and/or change the docs. |
Beta Was this translation helpful? Give feedback.
-
Hello I've got the same issue right now Thanks |
Beta Was this translation helpful? Give feedback.
I've found the solution.
If you do
console.log(func)
you will get[Function (anonymous)]
. And if youconsole.log(func())
you will getPromise { <pending> }
so it makes sense toawait
but it also works with onlyfunc()
.However it does not work without
async
becausefunc
is a promise.@RomainLanz this does not seem like how it should work. If you point me to the right direction I can check the source code for this and check why it is behaving like this and/or change the docs.