Software zum Installieren eines Smart-Mirror Frameworks , zum Nutzen von hochschulrelevanten Informationen, auf einem Raspberry-Pi.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

no-try-expect.md 1.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. # Prevent catch assertions in tests (`no-try-expect`)
  2. ## Deprecated
  3. This rule has been deprecated in favor of
  4. [`no-conditional-expect`](no-conditional-expect.md).
  5. ---
  6. This rule prevents the use of `expect` inside `catch` blocks.
  7. ## Rule Details
  8. Expectations inside a `catch` block can be silently skipped. While Jest provides
  9. an `expect.assertions(number)` helper, it might be cumbersome to add this to
  10. every single test. Using `toThrow` concisely guarantees that an exception was
  11. thrown, and that its contents match expectations.
  12. The following patterns are warnings:
  13. ```js
  14. it('foo', () => {
  15. try {
  16. foo(); // `foo` may be refactored to not throw exceptions, yet still appears to be tested here.
  17. } catch (err) {
  18. expect(err).toMatch(/foo error/);
  19. }
  20. });
  21. it('bar', async () => {
  22. try {
  23. await foo();
  24. } catch (err) {
  25. expect(err).toMatch(/foo error/);
  26. }
  27. });
  28. it('baz', async () => {
  29. try {
  30. await foo();
  31. } catch (err) {
  32. expect(err).toMatchObject({ code: 'MODULE_NOT_FOUND' });
  33. }
  34. });
  35. ```
  36. The following patterns are not warnings:
  37. ```js
  38. it('foo', () => {
  39. expect(() => foo()).toThrow(/foo error/);
  40. });
  41. it('bar', async () => {
  42. await expect(fooPromise).rejects.toThrow(/foo error/);
  43. });
  44. it('baz', async () => {
  45. await expect(() => foo()).rejects.toThrow(
  46. expect.objectContaining({ code: 'MODULE_NOT_FOUND' }),
  47. );
  48. });
  49. ```