API Testing Documentation? #4745
Replies: 1 comment
-
I feel like I am getting a bit further, by just experimenting. I have found some docs at https://docs.adonisjs.com/guides/testing/http-tests import { test } from '@japa/runner'
test.group('Users list', () => {
test('example test', async ({ assert, client }) => {
const response = await client.get('/')
response.assertStatus(200)
})
}) I get the error [ info ] booting application to run tests...
Error: Cannot apply suites filter. "tests/functional/users/list.spec.ts" suite is not configured
⁃ Validator.validateSuitesFilter
node_modules\.pnpm\@japa+runner@3.1.4\node_modules\@japa\runner\src\validator.ts:66
⁃ new Planner
node_modules\.pnpm\@japa+runner@3.1.4\node_modules\@japa\runner\src\planner.ts:25
⁃ run
node_modules\.pnpm\@japa+runner@3.1.4\node_modules\@japa\runner\index.ts:165 Here is my bootstrap.ts import { assert } from '@japa/assert'
import { apiClient } from '@japa/api-client'
import app from '@adonisjs/core/services/app'
import type { Config } from '@japa/runner/types'
import { pluginAdonisJS } from '@japa/plugin-adonisjs'
import testUtils from '@adonisjs/core/services/test_utils'
/**
* This file is imported by the "bin/test.ts" entrypoint file
*/
/**
* Configure Japa plugins in the plugins array.
* Learn more - https://japa.dev/docs/runner-config#plugins-optional
*/
export const plugins: Config['plugins'] = [assert(), apiClient(), pluginAdonisJS(app)]
/**
* Configure lifecycle function to run before and after all the
* tests.
*
* The setup functions are executed before all the tests
* The teardown functions are executed after all the tests
*/
export const runnerHooks: Required<Pick<Config, 'setup' | 'teardown'>> = {
setup: [],
teardown: [],
}
/**
* Configure suites by tapping into the test suite instance.
* Learn more - https://japa.dev/docs/test-suites#lifecycle-hooks
*/
export const configureSuite: Config['configureSuite'] = (suite) => {
if (['browser', 'functional', 'e2e'].includes(suite.name)) {
return suite.setup(() => testUtils.httpServer().start())
}
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Is there any documentation for API testing. I'm not sure if the functional testing is only for full stack Adonis apps.
When it comes to unit testing, I can't find anything relating to testing controller methods. Am I better creating a service and calling those service methods from the controller, but I can't find any docs relating to controller/service design, so I assume your supposed to test API controllers directly??
Beta Was this translation helpful? Give feedback.
All reactions