async-spec-helpers.js 886 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. /** @babel */
  2. export function beforeEach (fn) {
  3. global.beforeEach(function () {
  4. const result = fn()
  5. if (result instanceof Promise) {
  6. waitsForPromise(() => result)
  7. }
  8. })
  9. }
  10. export function afterEach (fn) {
  11. global.afterEach(function () {
  12. const result = fn()
  13. if (result instanceof Promise) {
  14. waitsForPromise(() => result)
  15. }
  16. })
  17. }
  18. ['it', 'fit', 'ffit', 'fffit'].forEach(function (name) {
  19. module.exports[name] = function (description, fn) {
  20. global[name](description, function () {
  21. const result = fn()
  22. if (result instanceof Promise) {
  23. waitsForPromise(() => result)
  24. }
  25. })
  26. }
  27. })
  28. function waitsForPromise (fn) {
  29. const promise = fn()
  30. global.waitsFor('spec promise to resolve', function (done) {
  31. promise.then(done, function (error) {
  32. jasmine.getEnv().currentSpec.fail(error)
  33. done()
  34. })
  35. })
  36. }