-
-
Notifications
You must be signed in to change notification settings - Fork 17
Can't test against data that already exists using trait('DatabaseTransaction') #15
Comments
Here is my attempt with Factory mocks, now I get a connection error from what I can only perceive to be the client handler. 'use strict'
const { test, trait } = use('Test/Suite')('City')
const City = use('App/Models/City')
const Factory = use('Factory')
trait('DatabaseTransactions')
trait('Test/ApiClient')
test('get list of cities', async ({ client }) => {
const city = await Factory.model('App/Models/City').create()
const response = await client.get('/api/v1/cities').end()
response.assertStatus(200)
response.assertJSONSubset([{
code: city.code,
name: cide.name
}])
}) Here is what the test runner's output:
Realizing now, this may have something to do with the fact that I'm using Nuxt.js and starting from an igniter and not the standard CLI command. Not sure how this could mess stuff up exactly? Sorry if this is n00b question, I'm very interested in this framework and will be willing to submit a pull request if I can find the issue myself. |
Hey @SeedyROM! 👋 Simply define an |
I'm a complete idiot, I skimmed over that document so hard! Thanks for the clarification! Also thanks for the late (PST) reply. I will try that and close this issue. Hope other half-awake noobies find this question. 👌🏻🔥 |
Thank you for marking this as a question and not an issue, that was my mistake. So I've done what you've said (I also made a new DB for testing only, maybe this isn't correct?), but how do I run migrations for the test DB? I'm getting an error saying the tables simply don't exist, which makes sense since the migrations haven't been run. I'm obviously missing something important. The docs shed no light on this from what I can see while perusing around.
Thanks again for the timely responses. |
https://github.com/adonisjs/adonis-blog-demo/blob/master/vowfile.js#L36 This is the correct setup for my testing purposes, I missed this link as well. Please close this issue and have a good night! |
Yeah, those lines are commented by default in your |
I generated this app from a nuxt-create-app, which is clearly the main problem here! I will add an issue/question on Nuxt's repo to clarify this. I've obviously done way more modifications to the default template than testing, but this one bit me harder than any other. Thanks so much for the clarifications! |
I'm like 3 hours new to Adonis and I'm having trouble testing a simple list view that should return JSON.
Since the data already exists in my database, I get:
Is there anyway to run tests in a different database? Something like in django or rails when you have a
adonis_test
database?Here is my test code just incase I'm missing something important!
Do I need to use mocks for these? I think that's what I'm missing but there's not much information on it that I can find from cursory google searches.
The text was updated successfully, but these errors were encountered: