diff --git a/closure/goog/testing/i18n/asserts.js b/closure/goog/testing/i18n/asserts.js index a148eacfff..14dfe22380 100644 --- a/closure/goog/testing/i18n/asserts.js +++ b/closure/goog/testing/i18n/asserts.js @@ -121,6 +121,7 @@ goog.testing.i18n.asserts.assertI18nEquals = function(a, b, opt_c) { /** * Asserts that needle, or a string i18n-equivalent to needle, is a substring of * haystack. I18n-equivalent strings are set with addI18nMapping. + * Horizontal white space is removed before comparison. * * @param {string} needle The substring to search for. * @param {string} haystack The string to search within. @@ -136,7 +137,11 @@ goog.testing.i18n.asserts.assertI18nContains = function(needle, haystack) { return; } - assertContains(needle, haystack); + const wsFixedNeedle = goog.testing.i18n.whitespace.removeWhitespace(needle); + const wsFixedHaystack = + goog.testing.i18n.whitespace.removeWhitespace(haystack); + + assertContains(wsFixedNeedle, wsFixedHaystack); }; diff --git a/closure/goog/testing/i18n/asserts_test.js b/closure/goog/testing/i18n/asserts_test.js index b9ee11bbe3..f79839b05e 100644 --- a/closure/goog/testing/i18n/asserts_test.js +++ b/closure/goog/testing/i18n/asserts_test.js @@ -89,6 +89,15 @@ testSuite({ assertThrowsJsUnitException(() => { asserts.assertI18nEquals('mappedValue', '** dummy'); }); + + // Check for containing with horizontal space matching + + asserts.assertI18nContains('abc', ' abc\u1680'); + asserts.assertI18nContains('abc', '\u202fabc \u3000'); + asserts.assertI18nContains('abc', '\u202fabc \u3000'); + asserts.assertI18nContains('a b c', '\u202fabc \u3000'); + asserts.assertI18nContains('a\u202fb\t\xA0c', '\u202fabc \u3000'); + }, testMappingWorks() {