jasmine.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /* eslint-disable import/prefer-default-export */
  2. var currentSpec;
  3. export function spec() {
  4. return currentSpec;
  5. };
  6. beforeEach(function() {
  7. currentSpec = this;
  8. var matchers = {
  9. toBeInArray() {
  10. return {
  11. compare(actual, expected) {
  12. return {
  13. pass: Array.isArray(expected) && expected.indexOf(actual) > -1
  14. };
  15. }
  16. };
  17. },
  18. toBeFunction() {
  19. return {
  20. compare(actual, expected) {
  21. return {
  22. pass: typeof actual === 'function'
  23. };
  24. }
  25. };
  26. },
  27. toBeAroundValue() {
  28. return {
  29. compare(actual, expected, diff) {
  30. diff = diff || 1;
  31. var pass = actual >= expected - diff && actual <= expected + diff;
  32. var message = `Expected ${actual} to be around ${expected} (between ${expected - diff} and ${expected + diff})`;
  33. if (!pass) {
  34. message = `Expected ${actual} NOT to be around ${expected} (between ${expected - diff} and ${expected + diff})`;
  35. }
  36. return {
  37. pass,
  38. message
  39. };
  40. }
  41. };
  42. }
  43. };
  44. jasmine.addMatchers(matchers);
  45. if (document.activeElement && document.activeElement != document.body) {
  46. document.activeElement.blur();
  47. } else if (!document.activeElement) { // IE
  48. document.body.focus();
  49. }
  50. });
  51. afterEach(() => {
  52. window.scrollTo(0, 0);
  53. });