Ok, the solution was (it was one of my coworker's solution really).
In the Vitest config/setup file import expect and add the following:
import { expect /* and other imports */ } from 'vitest';
expect.addSnapshotSerializer({
test: (val) => typeof val === 'string',
print: (val) => `"${(val as string).replace(/css-[a-z0-9]*/g, 'css-test')}"`,
});
This will replace the hashed css classes with "css-test". 🙂