Skip to content

Open-Source API Development Ecosystem • https://hoppscotch.io • Offline, On-Prem & Cloud • Web, Desktop & CLI • Open-Source Alternative to Postman, Insomnia

refactor: update test components to use setup scripts

Andrew Bastine9043e67627a
diff --git a/components/http/TestResult.vue b/components/http/TestResult.vue
index 1201580f6..4a5051376 100644
--- a/components/http/TestResult.vue
+++ b/components/http/TestResult.vue
@@ -120,36 +120,26 @@
</AppSection>
</template>
-<script lang="ts">
-import { defineComponent } from "@nuxtjs/composition-api"
+<script setup lang="ts">
+import { computed } from "@nuxtjs/composition-api"
import { useReadonlyStream } from "~/helpers/utils/composables"
import { restTestResults$, setRESTTestResults } from "~/newstore/RESTSession"
-export default defineComponent({
- setup() {
- return {
- testResults: useReadonlyStream(restTestResults$, null),
- }
- },
- computed: {
- totalTests(): number | undefined {
- return this.testResults?.expectResults.length
- },
- failedTests(): number | undefined {
- return this.testResults?.expectResults.filter(
- (result: { status: string }) => result.status === "fail"
- ).length
- },
- passedTests(): number | undefined {
- return this.testResults?.expectResults.filter(
- (result: { status: string }) => result.status === "pass"
- ).length
- },
- },
- methods: {
- clearContent() {
- setRESTTestResults(null)
- },
- },
-})
+const testResults = useReadonlyStream(restTestResults$, null)
+
+const totalTests = computed(() => testResults.value?.expectResults.length)
+const failedTests = computed(
+ () =>
+ testResults.value?.expectResults.filter(
+ (result: { status: string }) => result.status === "fail"
+ ).length
+)
+const passedTests = computed(
+ () =>
+ testResults.value?.expectResults.filter(
+ (result: { status: string }) => result.status === "pass"
+ ).length
+)
+
+const clearContent = () => setRESTTestResults(null)
</script>
diff --git a/components/http/Tests.vue b/components/http/Tests.vue
index 85b16295a..526361c24 100644
--- a/components/http/Tests.vue
+++ b/components/http/Tests.vue
@@ -72,7 +72,7 @@
</h4>
<div class="flex flex-col pt-4">
<TabSecondary
- v-for="(snippet, index) in snippets"
+ v-for="(snippet, index) in testSnippets"
:key="`snippet-${index}`"
:label="snippet.name"
active
@@ -84,29 +84,17 @@
</AppSection>
</template>
-<script lang="ts">
-import { defineComponent } from "@nuxtjs/composition-api"
+<script setup lang="ts">
import { useTestScript } from "~/newstore/RESTSession"
import testSnippets from "~/helpers/testSnippets"
-export default defineComponent({
- setup() {
- const testScript = useTestScript()
+const testScript = useTestScript()
- const useSnippet = (script: string) => {
- testScript.value += script
- }
+const useSnippet = (script: string) => {
+ testScript.value += script
+}
- const clearContent = () => {
- testScript.value = ""
- }
-
- return {
- testScript,
- snippets: testSnippets,
- useSnippet,
- clearContent,
- }
- },
-})
+const clearContent = () => {
+ testScript.value = ""
+}
</script>