web 3d图形渲染器
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.

56 lines
1.3 KiB

  1. # Enforce valid `describe()` callback (`valid-describe`)
  2. Using an improper `describe()` callback function can lead to unexpected test
  3. errors.
  4. ## Rule Details
  5. This rule validates that the second parameter of a `describe()` function is a
  6. callback function. This callback function:
  7. - should not be
  8. [async](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/async_function)
  9. - should not contain any parameters
  10. - should not contain any `return` statements
  11. The following `describe` function aliases are also validated:
  12. - `describe`
  13. - `describe.only`
  14. - `describe.skip`
  15. - `fdescribe`
  16. - `xdescribe`
  17. The following patterns are considered warnings:
  18. ```js
  19. // Async callback functions are not allowed
  20. describe('myFunction()', async () => {
  21. // ...
  22. });
  23. // Callback function parameters are not allowed
  24. describe('myFunction()', done => {
  25. // ...
  26. });
  27. //
  28. describe('myFunction', () => {
  29. // No return statements are allowed in block of a callback function
  30. return Promise.resolve().then(() => {
  31. it('breaks', () => {
  32. throw new Error('Fail');
  33. });
  34. });
  35. });
  36. ```
  37. The following patterns are not considered warnings:
  38. ```js
  39. describe('myFunction()', () => {
  40. it('returns a truthy value', () => {
  41. expect(myFunction()).toBeTruthy();
  42. });
  43. });
  44. ```