async-spec-helpers.js 972 B

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