Skip to content
This repository was archived by the owner on Aug 1, 2024. It is now read-only.

Commit 11ed104

Browse files
Closure Teamcopybara-github
authored andcommitted
Update I18N test with assert that works better with null/empty actual values. ignores white space differences.
RELNOTES: Update I18N test with assert that works better with null/empty actual values. PiperOrigin-RevId: 494955128 Change-Id: I87fc665aeb54b857cbbcea6dfbd695d7e0acbcdd
1 parent 5fa11c8 commit 11ed104

File tree

2 files changed

+55
-30
lines changed

2 files changed

+55
-30
lines changed

closure/goog/testing/i18n/asserts.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ goog.testing.i18n.asserts.assertI18nEquals = function(a, b, opt_c) {
7272
let actual;
7373
let msg; // The comment to be added, if any
7474
// If there are 3 arguments, the first is a comment.
75-
if (opt_c) {
75+
if (arguments.length === 3) {
7676
msg = a;
7777
expected = b;
7878
actual = opt_c;
@@ -87,8 +87,10 @@ goog.testing.i18n.asserts.assertI18nEquals = function(a, b, opt_c) {
8787

8888
// Compare with all horizontal white space characters removed, making
8989
// this less brittle.
90-
let wsFixedActual = actual.replace(
91-
goog.testing.i18n.asserts.HORIZONTAL_WHITE_SPACE_REGEX, '');
90+
let wsFixedActual = actual ?
91+
actual.replace(
92+
goog.testing.i18n.asserts.HORIZONTAL_WHITE_SPACE_REGEX, '') :
93+
actual;
9294

9395
// Now, check if the expected string and the actual result differ only
9496
// in whitespace by stripping white space characters from each.

closure/goog/testing/i18n/asserts_test.js

Lines changed: 50 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -11,43 +11,72 @@
1111
goog.module('goog.testing.i18n.assertsTest');
1212
goog.setTestOnly();
1313

14-
const ExpectedFailures = goog.require('goog.testing.ExpectedFailures');
1514
const asserts = goog.require('goog.testing.i18n.asserts');
1615
const testSuite = goog.require('goog.testing.testSuite');
1716

1817
// Add this mapping for testing only
1918
asserts.addI18nMapping('mappedValue', 'newValue');
2019
asserts.addI18nMapping('X\u0020Y', 'AB');
2120

22-
let expectedFailures;
23-
2421
testSuite({
25-
setUpPage() {
26-
expectedFailures = new ExpectedFailures();
27-
},
28-
29-
tearDown() {
30-
expectedFailures.handleTearDown();
31-
},
32-
3322
/** @suppress {checkTypes} suppression added to enable type checking */
3423
testEdgeCases() {
3524
// Pass
3625
asserts.assertI18nEquals(null, null);
3726
asserts.assertI18nEquals('', '');
3827

3928
// Fail
40-
expectedFailures.expectFailureFor(true);
41-
try {
29+
assertThrowsJsUnitException(() => {
4230
asserts.assertI18nEquals(null, '');
31+
});
32+
assertThrowsJsUnitException(() => {
4333
asserts.assertI18nEquals(null, 'test');
34+
});
35+
assertThrowsJsUnitException(() => {
4436
asserts.assertI18nEquals('', null);
37+
});
38+
assertThrowsJsUnitException(() => {
4539
asserts.assertI18nEquals('', 'test');
40+
});
41+
assertThrowsJsUnitException(() => {
4642
asserts.assertI18nEquals('test', null);
43+
});
44+
assertThrowsJsUnitException(() => {
4745
asserts.assertI18nEquals('test', '');
48-
} catch (e) {
49-
expectedFailures.handleException(e);
50-
}
46+
});
47+
},
48+
49+
/** @suppress {checkTypes} suppression added to enable type checking */
50+
testEdgeCases_withComments() {
51+
// Pass
52+
asserts.assertI18nEquals('Expect null values to match.', null, null);
53+
asserts.assertI18nEquals('Expect empty values to match.', '', '');
54+
55+
// Fail
56+
assertThrowsJsUnitException(() => {
57+
asserts.assertI18nEquals(
58+
'Expect null and empty values to not match.', null, '');
59+
});
60+
assertThrowsJsUnitException(() => {
61+
asserts.assertI18nEquals(
62+
'Expect null and non-empty values to not match.', null, 'test');
63+
});
64+
assertThrowsJsUnitException(() => {
65+
asserts.assertI18nEquals(
66+
'Expect empty and null values to not match.', '', null);
67+
});
68+
assertThrowsJsUnitException(() => {
69+
asserts.assertI18nEquals(
70+
'Expect empty and non-empty values to not match.', '', 'test');
71+
});
72+
assertThrowsJsUnitException(() => {
73+
asserts.assertI18nEquals(
74+
'Expect non-empty and null values to not match.', 'test', null);
75+
});
76+
assertThrowsJsUnitException(() => {
77+
asserts.assertI18nEquals(
78+
'Expect non-empty and empty values to not match.', 'test', '');
79+
});
5180
},
5281

5382
testContains() {
@@ -57,12 +86,9 @@ testSuite({
5786
asserts.assertI18nContains('mappedValue', '** newValue');
5887

5988
// Negative testing
60-
expectedFailures.expectFailureFor(true);
61-
try {
62-
asserts.assertI18nContains('mappedValue', '** dummy');
63-
} catch (e) {
64-
expectedFailures.handleException(e);
65-
}
89+
assertThrowsJsUnitException(() => {
90+
asserts.assertI18nEquals('mappedValue', '** dummy');
91+
});
6692
},
6793

6894
testMappingWorks() {
@@ -72,12 +98,9 @@ testSuite({
7298
asserts.assertI18nEquals('mappedValue', 'newValue');
7399

74100
// Negative testing
75-
expectedFailures.expectFailureFor(true);
76-
try {
101+
assertThrowsJsUnitException(() => {
77102
asserts.assertI18nEquals('unmappedValue', 'newValue');
78-
} catch (e) {
79-
expectedFailures.handleException(e);
80-
}
103+
});
81104
},
82105

83106
testWhiteSpaceStringWorks() {

0 commit comments

Comments
 (0)