Questions tagged [snapshot-testing]

A mechanism to assist automated unit testing of visual components by generating a 'snapshot' of the component and then comparing the rendered component with the saved snapshot.

Snapshot testing was popularised by test frameworks like Jest, used to test React components in isolation. The test framework renders a 'snapshot' to a static file and then, in subsequent tests, the newly rendered component is compared to the saved snapshot. This saves a lot of test development effort.

52 questions
26
votes
2 answers

When should I use Snapshot testing?

It's fairly easy to implement snapshot testing in jest, but it's something I am not really comfortable with because it feels like I am not actually testing anything. In unit testing I can easily take components I want to test and write expectations…
bigfanjs
  • 754
  • 3
  • 7
  • 17
9
votes
1 answer

TypeError: Cannot read properties of undefined (reading 'addEventListener') with StoryShots Storybook

I'm using Storyshots with storybook for snapshot testing. Referred to the documentation here: link1, link2 The complete error log Followed all the steps here, but don't know why the error is coming :) You can find the code here I have also searched…
5
votes
0 answers

Jest snapshot tests pass locally but fail on Jenkins

I have a series of snapshot tests that pass locally. But on Jenkins, my component seems to be rendering a different snapshot. My tests are: import { render } from 'enzyme'; import React from 'react'; import Wizard from…
Athanasia
  • 51
  • 3
5
votes
1 answer

Snapshot testing using Karma Angular and not jest

Apologies if the question sounds incomplete. I have learnt NgRx recently and realized that snapshot testing would make life easier compared to asserting in case of NgRx. However, i don't want to migrate from Karma to Jest (don't want to change the…
3
votes
1 answer

Suppress all warnings from my SPM package

Is there a way to suppress all warnings coming from my SPM Package in XCode?! ⚠️found 1 file(s) which are unhandled; explicitly declare them as resources or exclude from the target This warning shows because my SPM package contains .txt file. I…
3
votes
2 answers

Snapshot Integration for Jasmine + Karma Test Framework (Angular Project)

I have been researching a lot about using Jasmine and Karma for testing an Angular project. I am currently looking at the possibility of integrating a snapshot library for the said test framework. However, I have so far only found this library, last…
3
votes
1 answer

How to snapshot-test a component that does async data loading using react-testing-library?

So far, in the projects I'm working on, I usually snapshot-test my components that does async data loading this way: describe('MyComponent component', () =>{ test('Matches snapshot', async () => { …
Thanaen
  • 159
  • 2
  • 10
2
votes
1 answer

Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: object. You likely

Try to snapshot a Logo component but got an error that is not properait as far as i understand. Pleas help! logo.test.js import TestRenderer from 'react-test-renderer'; import Logo from '../components/Common/Logo'; describe('Snapshot Logo…
2
votes
1 answer

Storybook Addon StoryShots for Angular 12

I will install Snapshot Testing with Storybook under Angular 12. I install jest $ yarn add --dev jest jest-preset-angular @types/jest and make Settings "jest": { "preset": "jest-preset-angular", "setupFilesAfterEnv":…
2
votes
1 answer

How to format HTML returned by Verify.PlayWright for better comparison

I am using Verify.PlayWright and to take HTML element snapshots. When the compare opens, all the HTML is on one line. This makes it hard to see the differences. Is there a way to format the HTML in order to get a nicer comparison? var root = await…
2
votes
1 answer

Testing Dark Mode using snapshot testing

Any leads how can we use Snapshot testing to test darkmode implementation? Or any other testing strategy for dark mode on iOS. When XCUITest is one of the options along with XCTest (unit-test). The problem with UITest in dark mode means for every…
2
votes
1 answer

Jest snapshot testing fail in GitLab pipeline due to timezone mismatch

I have normal Jest snapshot tests for a component that calls toDateString() and toTimeString(). The tests all pass when I run locally because both the tests and my component run in my current time zone (EST); however, when I check the tests into…
telemo
  • 21
  • 2
2
votes
0 answers

"Warning: An invalid container has been provided" in Jest

I have following tests: describe('if initialized', () => { const loadProjects = jest.fn(); let tree: ReactTestRenderer | null; renderer.act(() => { tree = renderer.create(
Tomasz Waszczyk
  • 2,680
  • 5
  • 35
  • 73
1
vote
0 answers

How to snapshot test Swift Package Manager (SPM) that contains SwiftUI views

We are breaking the app in a modular way and extracted the UI in a SwiftPM. It only contains SwiftUI views and nothing more. We successfully included the Pointfree snapshot library into the SPM. The issue comes when we try to run the tests. When we…
1
vote
0 answers

Snapshot test for a React component with `useId` is fragile

I create a component with useId as follows: function Form() { const id = useId(); return (
); } When I ran a snapshot test, I got a snapshot like the…
1
2 3 4