Guest User

Untitled

a guest
Nov 21st, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. (function() {
  2.  
  3. 'use strict';
  4. angular.module('schedules')
  5. .factory('TimeServiceMatchers', TimeServiceMatchers);
  6.  
  7. TimeServiceMatchers.$inject = [];
  8.  
  9. function TimeServiceMatchers() {
  10. return {
  11. getMatchers: getMatchers
  12. }
  13.  
  14. function getMatchers() {
  15. return {
  16. toEndIn: toEndIn,
  17. toHaveMinutesOf30or00: toHaveMinutesOf30or00
  18. }
  19. }
  20. function toEndIn() {
  21. return {
  22. compare: compare
  23. }
  24. function compare(actual, expected) {
  25. const aOrP = expected.replace(/[m]/, '');
  26. const reversedArray = actual.split('').reverse();
  27. return {
  28. pass: (reversedArray[0] === 'm' && reversedArray[1] === aOrP),
  29. message: actual + ' does not end in ' + aOrP + 'm'
  30. };
  31. }
  32. }
  33.  
  34. function toHaveMinutesOf30or00() {
  35. return {
  36. compare: compare
  37. }
  38. function compare(actual) {
  39. const minutes = actual.replace(/.*:/, '').replace(/(am|pm)/gi, '');
  40. return {
  41. pass: (minutes === '30' || minutes === '00'),
  42. message: actual + ' does not have minutes of 30 or 00'
  43. };
  44. }
  45. }
  46.  
  47. }
  48.  
  49. })();
Add Comment
Please, Sign In to add comment