chaidom.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import $ from 'jquery';
  2. import env from '../src/js/base/core/env';
  3. export default function(chai) {
  4. chai.dom = chai.dom || {};
  5. chai.dom.equalsIgnoreCase = function(str1, str2) {
  6. str1 = str1.toUpperCase();
  7. str2 = str2.toUpperCase();
  8. // [workaround] IE8-10 use   instead of bogus br
  9. if (env.isMSIE && env.browserVersion < 11) {
  10. str2 = str2.replace(/<BR\/?>/g, '&NBSP;');
  11. str1 = str1.replace(/<BR\/?>/g, '&NBSP;');
  12. }
  13. // [workaround] IE8 str1 markup has newline between tags
  14. if (env.isMSIE && env.browserVersion < 9) {
  15. str1 = str1.replace(/\r\n/g, '');
  16. }
  17. return str1 === str2;
  18. };
  19. chai.dom.equalsStyle = function($node, expected, style) {
  20. var $tester = $('<div />').css(style, expected);
  21. return $node.css(style) === $tester.css(style);
  22. };
  23. chai.Assertion.addChainableMethod('equalsIgnoreCase', function(expected) {
  24. var actual = this._obj;
  25. return this.assert(
  26. chai.dom.equalsIgnoreCase(actual, expected),
  27. 'expected ' + this._obj + ' to equal ' + expected + ' ignoring case',
  28. 'expected ' + this._obj + ' not to equal ' + expected + ' ignoring case'
  29. );
  30. });
  31. chai.Assertion.addChainableMethod('equalsStyle', function(expected, style) {
  32. var $node = this._obj;
  33. return this.assert(
  34. chai.dom.equalsStyle($node, expected, style),
  35. 'expected ' + this._obj + ' to equal ' + expected + ' style',
  36. 'expected ' + this._obj + ' not to equal ' + expected + ' style'
  37. );
  38. });
  39. chai.assert.equalsIgnoreCase = function(val, exp, msg) {
  40. new chai.Assertion(val, msg).to.be.equalsIgnoreCase(exp);
  41. };
  42. chai.assert.notequalsIgnoreCase = function(val, exp, msg) {
  43. new chai.Assertion(val, msg).to.not.be.equalsIgnoreCase(exp);
  44. };
  45. }