919 questions
0
votes
0
answers
180
views
Vitest setup file is not working in bun express application
I have this bun expressjs typescript application and this is my folder structure.
I wrote some tests using vitest which are placed in the tests/ directory and the tests are executing perfectly with ...
-1
votes
1
answer
239
views
vi.spyOn(reactRedux, 'useDispatch') is not working / "TypeError: Cannot redefine property: useDispatch"
I don't seem to find a solution for the below code / test to work (I went through a lot of articles and stackOverflow...). Various solutions provided by chatGPT are useless as well. I also see people ...
0
votes
0
answers
22
views
How can I unit test Graphql Upload in api using Vitest
I wrote a test which creates a Venue with attachments property which is of Graphql Upload type. But when I try to run the test, it fails with error "message": "Variable \"$...
0
votes
0
answers
136
views
ViTest Mock is not replacing function
For some reason in ViTest mocks are not replacing my real function. I have a main function here
const { handler1 } = require(./path/handler1)
exports.mainFunction = async (event) => {
try {
...
1
vote
1
answer
498
views
How to Access the Shadow DOM of a Custom Element in Vue Vitest
I’m working on a Vue component that contains a custom element with a shadow DOM. I want to test the content inside the shadow root of this custom element using Vue Test Utils. However, when I use ...
0
votes
0
answers
94
views
Storybook mock async function results in infinite loop
I'm setting up my Storybook stories I'm trying too mock a call to an API.
Here's the code:
import type { StoryObj, Meta } from '@storybook/react';
import { createMock, getMock } from 'storybook-addon-...
0
votes
1
answer
121
views
Vue3, Vuetify3, Vitest, Teleports not rendering
I was having a problem testing my application because vuetify3 uses teleports in their v-menus, v-dialogs, v-tooltips, etc. We can disable the teleports by using attach, but that breaks some of our ...
-4
votes
1
answer
235
views
createMemoryRouter throws TypeError: Cannot destructure property 'basename' of 'React10.useContext(...)' as it is null [closed]
Using createMemoryRouter to create router to render doesn't work. It renders and error page.
import { vi, describe, it, expect } from 'vitest'
import { render } from '@testing-library/react'
import { ...
0
votes
0
answers
35
views
Component unit testing in a nuxt module
First of all I have to say that the nuxt documentation for unit testing a nuxt module is sooo bad, me and all my colleagues are not able to create even a tiny unit test. So what I am trying to do is ...
0
votes
0
answers
179
views
Vitest: Module mocking in browser mode
Is there a special configuration I need for vi.mock('../src/some/file', ...) to work in browser mode?
Is it supported for a specific provider or browser?
I think it's implemented, but I can't get it ...
0
votes
1
answer
49
views
Why are attributes not rendered when using shallowMount in vue3 vitest
I ran into this problem when trying to generate tests using AI. It generated the tests with mount() and it works, but when you ask it to use shallowMount(), the attributes on tags are removed, and a ...
0
votes
1
answer
396
views
How to test a loading screen in vitest
In my <App /> component I want to show a loading screen until I've fetched my data and after fetching my data all the images(whose source's I got from my data) are loaded.
I am having difficulty ...
1
vote
0
answers
291
views
How to mock Nuxt 3 composables(useAsyncData & useRuntimeConfig) in unit tests
The page that I'm trying to write unit tests about is as follows:
<script setup lang="ts">
import { Content, fetchOneEntry, isPreviewing } from '@builder.io/sdk-vue'
import { useRoute }...
0
votes
1
answer
216
views
How to debug configuration issue with allure-vitest/reporter
I have simple test automation project with TypeScript + Vitest + allure-vitest reporter. I have tried to upgrade/downgrade main dependencies without any luck.
It works perfectly on one type of machine ...
0
votes
0
answers
541
views
How to setup Vitest with React Native / Expo? Getting: RollupError: Parse failure: Expected 'from', got 'typeof'
I can run my Vitest usually, but when I try to import a react native link, it breaks with the error below:
RollupError: Parse failure: Expected 'from', got 'typeof'
At file: /mobile-app/node_modules/...
0
votes
0
answers
171
views
Mocking a service/object without having to recreate the whole dependency tree
I'm building a browser library for consumption by our clients where they can include it in their site and utilize it to access our services, etc.
I am trying to set up unit testing for the library. ...
0
votes
3
answers
576
views
Is there a way to generate text coverage report for a single test file using Vitest & v8?
I have an npm script in the package.json:
"test:coverage": "vitest run --coverage",
Also, there is a hello.test.ts test file.
I want:
Vitest to run a single hello.test.ts file
...
1
vote
1
answer
1k
views
How to expect a promise to be resolved in vitest with custom error message
In vitest you can expect a Promise to be resolved using this code:
await expect(expected, "custom message").resolves.toBeUndefined()
However, when failing to resolve, the custom message is ...
0
votes
0
answers
178
views
Testing styled components from @emotion/styled with vitest
I am trying to assert that a component has a certain style in one of my tests. In the browser this component has the correct style but when I run my vitest test I get an incorrect style. It looks like ...
1
vote
1
answer
220
views
Typescript complains that vitests onTestFailed function is undefined despite of importing it
I'm trying to add additional information to failing tests in a bigger typescript project.
I found the onTestFailed hook that registers a callback function to a test.
So for a quick test, I followed ...
0
votes
0
answers
113
views
Vitest Unhandled Error During Test Run for with Cytoscape.js
I'm trying to write a test using Vitest for a function localComplement that modifies a graph represented using Cytoscape.js. Here's the function:
export function localComplement(cy: any, elements: ...
3
votes
1
answer
862
views
Mocking node:crypto return value with Vitest
I tried following another related post on this topic with the creator's same outcome.
Since its post is dead I'd like to try again if someone has an idea on how to mock the node:crypto function or ...
1
vote
1
answer
361
views
SyntaxError when migrating to vitest from jest
I am migrating a React application from craco/Jest to Vite/Vitest
The application also used AntDesign and before the test was running flawlessy.
React version is 18.20 .
NB we are trying to also mock ...
0
votes
1
answer
38
views
KDBXWeb Saving database works in browser, fails in UnitTest
I'm trying to understand kdbxweb, the database powering keeweb, compatible to Keepass.
I did setup a simple project using vite and vitest that creates, saves and loads a database.
Works like a charm ...
0
votes
0
answers
103
views
Find dynamic rendered HTML Object using Vitest
Im currently writing Unit test for a Vue component. The component renders the floorplan of a office. For that it generates an svg with the tables of the office. These are saved in a json.
The Vue ...