Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/joshnuss/svelte-kit-test-helpers
Testing utilities for SvelteKit
https://github.com/joshnuss/svelte-kit-test-helpers
svelte sveltekit testing vitest
Last synced: 24 days ago
JSON representation
Testing utilities for SvelteKit
- Host: GitHub
- URL: https://github.com/joshnuss/svelte-kit-test-helpers
- Owner: joshnuss
- Created: 2022-10-11T13:00:32.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2022-10-11T14:56:04.000Z (about 2 years ago)
- Last Synced: 2024-04-14T03:14:26.248Z (7 months ago)
- Topics: svelte, sveltekit, testing, vitest
- Language: JavaScript
- Homepage:
- Size: 36.1 KB
- Stars: 12
- Watchers: 3
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
## Test helpers for SvelteKit
Provides helper functions and matchers for testing SvelteKit endpoints.
Extracted from [Sky Cart](https://github.com/joshnuss/sky-cart)
## Request helper
A utility function for testing endpoints:
```javascript
// test/routes/index.test.js
import { request } from 'svelte-kit-test-helpers'
import { GET } from 'src/routes/+server.js'test('GET /', async () => {
const response = await request(GET)expect(response.status).toBe(200)
})
```It makes it easy to adjust the request by adding `cookies`, `headers`, `params` and `body`:
```javascript
// test/routes/index.test.js
import { request } from 'svelte-kit-test-helpers'
import { GET } from 'src/routes/+server.js'test('GET /', async () => {
const response = await request(GET, {
headers: {
authorization: 'secret'
},
cookies: {
accountId: '1234'
}
})expect(response.status).toBe(200)
})
```## Matchers
TODO: add examples
## License
MIT