question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[test-runner-mocha] implement snapshot testing

See original GitHub issue

chai-dom-diff offers snapshot testing via

expect(element).shadowDom.to.equalSnapshot()

This fails in web test runner. Proximal cause is that window.__mocha_context__ is undefined. (this is probably a karma API?)

@LarsDenBakker recommended implementing snapshots directly with mocha, without reference to karma’s globals.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:4
  • Comments:11 (8 by maintainers)

github_iconTop GitHub Comments

5reactions
LarsDenBakkercommented, Jun 12, 2021

@open-wc/semantic-dom-diff now also supports snapshot testing with WTR. Currently open-wc is in “prerelease” mode until the next version of lit is finalized. For now you can get the latest using the next tag for the testing package:

"@open-wc/testing": "next"

Note that snapshot testing is now async, so you need to await the assertion:

await expect(element).shadowDom.toEqualSnapshot();
5reactions
MaximePlanckecommented, Jan 13, 2021

Hi everyone,

Do you have any update on when the snapshot would be available with web test runner? I am having some issues with karma and @open-wc/testing (I have some commonJS packages and the preprocessors I tried to convert to esm does not seem to work with @open-wc/testing-karma).

My best bet was web test runner as it makes it very easy to convert CommonJS module with rollup but unfortunately my snapshot tests are not working.

Thank you 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

Snapshot Testing - Jest
Snapshot tests are a very useful tool whenever you want to make sure your UI does not change unexpectedly.
Read more >
Image Snapshot Testing with Mocha - Sebastian Landwehr
This testing approach is great for complex data like large strings, DOM content, or images. I wrote a package to use image snapshot...
Read more >
Use expectMetricsJsonToMatchSnapshot in stryker-parent With ...
How to use expectMetricsJsonToMatchSnapshot method in stryker-parent · Run stryker-parent automation tests on LambdaTest cloud grid · Accelerate Your Automation ...
Read more >
Creating snapshots in Jest for testing React applications
To write your first snapshot test, you will use the renderer module. This module renders the Document Object Model (DOM) element that will ......
Read more >
stryker-mutator/stryker - Gitter
Has anyone here recently tried to use Stryker with Quasar (quasar.dev), Vue, and Jest? I have perfectly functional tests with Jest on my...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found