Skip to content

Commit 8cd9e9a

Browse files
committed
test: add tests for auto-generated composables
1 parent b55323c commit 8cd9e9a

File tree

5 files changed

+43
-0
lines changed

5 files changed

+43
-0
lines changed

Diff for: test/composables.test.ts

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { URL, fileURLToPath } from 'node:url'
2+
import { describe, it, expect } from 'vitest'
3+
import { setup, $fetch } from '@nuxt/test-utils'
4+
5+
describe('auto-generated composables', async () => {
6+
await setup({
7+
server: true,
8+
rootDir: fileURLToPath(new URL('./fixtures/composables', import.meta.url)),
9+
})
10+
11+
it('generates composable based on config', async () => {
12+
const html = await $fetch('/')
13+
expect(html).toEqual(expect.stringMatching(/variant: (a|b)/))
14+
})
15+
})

Diff for: test/fixtures/composables/app.vue

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<template>
2+
<h1>Composables fixture</h1>
3+
<p>variant: {{ selectedVariants.value }}</p>
4+
</template>
5+
6+
<script setup lang="ts">
7+
const selectedVariants = useHeaderABTest()
8+
</script>

Diff for: test/fixtures/composables/nuxt.config.ts

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
export default defineNuxtConfig({
2+
modules: ['../../../src/module'],
3+
// @ts-ignore
4+
abTesting: {
5+
tests: [
6+
{
7+
id: 'header',
8+
variants: [
9+
{ id: 'a', value: 'a' },
10+
{ id: 'b', value: 'b' },
11+
],
12+
},
13+
],
14+
},
15+
})

Diff for: test/fixtures/composables/packages.json

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"private": true,
3+
"name": "composables",
4+
"type": "module"
5+
}
File renamed without changes.

0 commit comments

Comments
 (0)