🕵️ SicherheitslückenHak5: Hackers Just Poisoned the Rust Supply Chain | Threat Wire(01.09.2026 um 14:00 Uhr)
🕵️ SicherheitslückenHak5: Hackers Found a Way Into Humanoid Robots | Threat Wire(04.09.2026 um 15:04 Uhr)
🔧 AI Nachrichten Bits und so #1021 (Passwort für Laufwerk)(31.08.2026 um 22:15 Uhr)
🔧 AI Nachrichten Bits und so #1022 (Wie Weißbier)(06.09.2026 um 20:39 Uhr)
🍏 iOS / Mac OSHue-App 6.0 ist da: das sind die Neuerungen(07.09.2026 um 17:21 Uhr)
🕵️ SicherheitslückenHak5: Hackers Just Poisoned the Rust Supply Chain | Threat Wire(01.09.2026 um 14:00 Uhr)
🕵️ SicherheitslückenHak5: Hackers Found a Way Into Humanoid Robots | Threat Wire(04.09.2026 um 15:04 Uhr)
🔧 AI Nachrichten Bits und so #1021 (Passwort für Laufwerk)(31.08.2026 um 22:15 Uhr)
🔧 AI Nachrichten Bits und so #1022 (Wie Weißbier)(06.09.2026 um 20:39 Uhr)
🍏 iOS / Mac OSHue-App 6.0 ist da: das sind die Neuerungen(07.09.2026 um 17:21 Uhr)

🔧 Programmierung 🕛 kürzlich 4 Min Lesezeit
0

💡 Building a Nuxt 3 App with Pinia and Testing It with Cypress 🚀

↗ Quelle (dev.to)
🗣️ Stimme:
📑 Inhaltsübersicht

In this article, I'll walk you through a simple project using Nuxt 3 with Pinia for state management and Cypress for end-to-end testing. This project implements an interactive counter with actions and tests to ensure everything works as expected. If you're looking to explore these technologies or enhance your skills, this article is for you!









🏗️ Project Structure



Here’s an overview of the main files in the project:




CODE
/layouts
default.vue
/pages
index.vue
/stores
counter.ts
/tests
main.cy.js












✨ Global Layout: layouts/default.vue



This layout provides the base structure for the application, including a header, a footer, and a slot for the page content.




CODE
<template>
<header>
<h1>Pinia</h1>
<p>The intuitive store for Vue</p>
</header>

<template v-if="route.path !== '/'">
<router-link to="/">→ Back Home</router-link>
<hr/>
</template>

<slot/>
<hr/>

<footer>
<a href="https://github.com/posva/pinia">
<svg class="logo" fill="none" viewBox="0 0 14 14" xmlns="http://www.w3.org/2000/svg">
<path
clip-rule="evenodd"
d="M7.02751 0.333496C..."
fill="currentColor"
fill-rule="evenodd"
/>
</svg>
Github
</a> - by
<a href="https://github.com/posva">@posva</a> 2021
</footer>
</template>

<script lang="ts" setup>
import { useRoute } from "#app";
const route = useRoute();
</script>

<style scoped>
.logo {
width: 1.5rem;
height: 1.5rem;
color: white;
}
</style>












 🖼️ Home Page: pages/index.vue



The home page uses the Pinia store to display and interact with the counter.




CODE
<template>
<div>
<div style="margin: 1rem 0">
<PiniaLogo/>
</div>

<p>
This is an example store to test out devtools.
</p>

<h2>Counter Store</h2>

<p data-testid="counter-values">Counter: {{ counter.n }}. Double: {{ counter.double }}</p>

<p>Increment the Store:</p>
<button @click="counter.increment()" data-testid="increment">+1</button>
<button @click="counter.increment(10)">+10</button>
<button @click="counter.increment(100)">+100</button>
</div>
</template>

<script setup lang="ts">
import { useCounter } from "~/stores/counter";
import PiniaLogo from "~/components/PiniaLogo.vue";

const counter = useCounter();
</script>

<style scoped>
button {
margin-right: 0.5rem;
margin-left: 0.5rem;
}
</style>












📦 Pinia Store: stores/counter.ts



The store manages the application state, along with its actions and getters.




CODE
import {acceptHMRUpdate, defineStore} from "pinia";

const delay = (t: number) => new Promise(resolve => setTimeout(resolve, t))

export const useCounter = defineStore('counter', {
state: () => ({
n: 2,
incrementedTimes: 0,
decrementedTimes: 0,
numbers: [] as number[]
}),

getters: {
double: (state) => state.n * 2
},

actions: {
increment(amount: number = 1) {
this.incrementedTimes++
this.n += amount
},

changeMe() {
console.log('Change me to test HMR')
},

async fail() {
const n = this.n
await delay(1000)
this.numbers.push(n)
await delay(1000)

if (this.n !== n) {
throw new Error('Someone changed n !')
}
},

async decrementToZero(interval: number = 300) {
if (this.n <= 0) return

while (this.n > 0) {
this.$patch((state) => {
this.n--
state.decrementedTimes++
})
await delay(interval)
}
}
}
})

if (import.meta.hot) {
import.meta.hot.accept(acceptHMRUpdate(useCounter, import.meta.hot))
}












 🛠️ Testing with Cypress: cypress/e2e/main.cy.js



The tests verify that the counter works properly and that the Pinia store actions are correctly reflected in the UI.




CODE
const PORT = process.env.PORT || 3000;

describe("Pinia demo with counters", () => {
beforeEach(() => {
cy.visit(`http://localhost:${PORT}`);
});

it("works", () => {
cy.get("[data-testid=counter-values]")
.should("contain.text", "Counter: 2. Double: 4")
.wait(500)
.get("[data-testid=increment]")
.click()
.get("[data-testid=counter-values]")
.should("contain.text", "Counter: 3. Double: 6")
.get("[data-testid=increment]")
.click();
});
});












 🎯 Results



Running the tests with npx cypress open validates the behavior of the Pinia store and its interactions with the UI.

Vollständiger Original-Bericht
Ausführliche Details, Code-Beispiele & Hersteller-Stellungnahme auf dev.to.
↗ Original-Artikel auf dev.to lesen
Wie bewertest du diesen Beitrag?
1 Klick Feedback
Teilen mit Netzwerk & Team:

Community-Analysen & Experten-Meinungen 0

Verfasse deine eigene Analyse, teile Workarounds oder diskutiere diesen Vorfall im Blog.
Noch keine Community-Analyse verfasst. Markiere einen Textabschnitt oder klicke oben auf Eigene Analyse verfassen“!
Community Pulse: Relevanz-Einschätzung
1 Klick Experten-Votum
🔴 Akute Relevanz 0%
🟡 In Evaluierung 0%
🟢 Keine Auswirkung 0%
Spannende Innovation 0%
Verwandte Story-Cluster & Quellen (Vektor-KI)
Port 8095 Engine
1 Quelle
Hackers Just Poisoned the Rust Supply Chain | Threat Wire
1 Quelle
Hackers Found a Way Into Humanoid Robots | Threat Wire
1 Quelle
Bits und so #1021 (Passwort für Laufwerk)
Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten 💡 Building a Nuxt 3 App with Pinia and Testing It with Cypress 🚀

Thematisch verwandte Begriffe: Building, Nuxt, with, Pinia · 6 Treffer

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...