SpecHelper.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. beforeEach(function() {
  2. this.addMatchers({
  3. toImplement: function(extension) {
  4. var instance = this.actual;
  5. var notImplements = [];
  6. for (var m in extension.prototype) {
  7. if (typeof(extension.prototype[m]) == 'function' &&
  8. typeof (instance[ m ]) != 'function') {
  9. notImplements.push(m);
  10. }
  11. }
  12. this.message = function() {
  13. return '未实现接口:' + notImplements.join(', ');
  14. };
  15. return notImplements.length === 0;
  16. },
  17. toMatchPlain: function(expected) {
  18. var actual = this.actual;
  19. var match = true;
  20. for (var p in expected) {
  21. if (expected[ p ] !== actual[ p ]) {
  22. match = false;
  23. }
  24. }
  25. this.message = function() {
  26. return '字面量不符合预期';
  27. };
  28. return match;
  29. },
  30. toHaveSubString: function(expected) {
  31. var actual = this.actual;
  32. this.message = function() {
  33. return'未包含期望的子字符串';
  34. };
  35. return !!~actual.substr(expected);
  36. }
  37. });
  38. });