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.

Support use of Swal in Jest testing environment

See original GitHub issue

New feature motivation

A few days ago I was working on https://github.com/sweetalert2/sweetalert2-react-content/pull/72, and when I left it, the last commit (https://github.com/sweetalert2/sweetalert2-react-content/pull/72/commits/33fe8d658e48c466325e77dde8b33488519c8cfc) had passing tests.

When I came back to it a couple days later, the same commit had failing tests due to the v8.2.3 patch release.

I managed to reproduce the bug in the swal-not-resolve-in-jest-bug repo. You can see that the build for the master branch (using sweetalert v8.2.2) is passing, but the build for the upgrade-sweetalert2-to-v8.2.3 branch is failing, due to the swal instance never resolving. (No idea why to be honest… at first glance, the changes from v8.2.2 to v8.2.3 don’t seem like they would cause this kind of problem)

Jest is an incredible testing tool, and it would be nice if sweetalert2 was supported [consistently] in this environment.

New feature

I propose to add first-class support for Jest, by doing the following things:

  1. Add check:jest to the package scripts, with only one or two very basic tests, as “smoke testing” for the Jest environment. Fine-grained testing of functionality should continue to happen only in the existing karma+qunit test environment.
  2. Debug and fix the above mentioned problem (reproduced in https://github.com/sweetalert2/swal-not-resolve-in-jest-bug).
  3. Not strictly needed, but would make testing in Jest nicer: Check for existence of window.scrollTo before calling it, to avoid the need to mock it here: https://github.com/sweetalert2/swal-not-resolve-in-jest-bug/blob/f06bbd41dc51716810cd274e5e4efa7e581d5383/test.js#L4-L7

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:7 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
limontecommented, Mar 11, 2019

🎉 This issue has been resolved in version 8.3.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

1reaction
SimenBcommented, Mar 8, 2019

The code coverage dropped to 62%

While the code coverage certainly should be higher, it’s also a bit misleading here. Jest has ~500 separate integration tests which spawns up an instance of Jest on different tests and scenarios and performs asserts on its output. This is not something that’s reflected in the code coverage numbers, as those are just from unit tests. So, while I agree ~60% is lower than it could (and should) be, the code base is better covered by tests than that number indicates.

https://github.com/facebook/jest/tree/master/e2e/__tests__

the Travis CI dashboard is still as red as the Chinese communist parade.

Note that Jest does not run tests from master in Travis (see your screenshot, the last build is 4 months ago), since travis thinks we inject some secret, turns off tty, which means all colors are borked (https://github.com/travis-ci/travis-ci/issues/7967#issuecomment-358437261). We run on PRs though to verify Jest itself works on Travis, since they are from forks they are not privileged. We run tests for node 6, 8, 10 and 11 on Linux on circleci, node 10 for windows, mac and linux on Azure pipelines and node 10 on appveyor for windows (we’ll remove that last one at some point since it’s covered by azure). All of which are green (or in progress at the time of writing)

https://circleci.com/gh/facebook/jest/tree/master https://dev.azure.com/jestjs/jest/_build?definitionId=1 (I’m not sure how to filter to just master there)

image

Read more comments on GitHub >

github_iconTop Results From Across the Web

How do I mock a third party package with Jest? - Stack Overflow
I think my mock needs to return a named method, so I can spyOn it and check that it was called. My test:...
Read more >
React Testing Library With Sweetalert Title - ADocLib
I have the following sweet alert 2 message: <button onclick' Swal.fire{ title: Select a page you want to be Can't compile js.erb imported...
Read more >
Need help testing a utility using Jest (not getting full coverage ...
I am attempting to test a simple logout() function using Jest. here is the logout function: import store from 'Redux/store'; import swal ......
Read more >
sweetalert2 | Yarn - Package Manager
A beautiful, responsive, customizable and accessible (WAI-ARIA) replacement for JavaScript's popup boxes, supported fork of sweetalert.
Read more >
How to get started writing unit tests for React with jest ... - JS.dev
Not every testing library is created equally though, and there is significant complexity within React applications that are just too difficult ...
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