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

Commit 5699bf2

Browse files
12wrigjashicks
authored andcommitted
Adjust Autocomplete test that fails in strict mode.
RELNOTES: n/a PiperOrigin-RevId: 329049751
1 parent 5b0ccb3 commit 5699bf2

File tree

1 file changed

+23
-4
lines changed

1 file changed

+23
-4
lines changed

closure/goog/ui/ac/richremotearraymatcher_test.js

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
goog.module('goog.ui.ac.RichRemoteArrayMatcherTest');
88
goog.setTestOnly();
99

10+
const ArgumentMatcher = goog.require('goog.testing.mockmatchers.ArgumentMatcher');
1011
const MockControl = goog.require('goog.testing.MockControl');
1112
const NetXhrIo = goog.require('goog.testing.net.XhrIo');
1213
const RichRemoteArrayMatcher = goog.require('goog.ui.ac.RichRemoteArrayMatcher');
@@ -18,8 +19,26 @@ const url = 'http://www.google.com';
1819
const token = 'goog';
1920
const maxMatches = 5;
2021

21-
const responseJsonText = '[["type1", "eric", "larry", "sergey"]]';
22-
const responseJsonType1 = ['eric', 'larry', 'sergey'];
22+
const responseJsonText =
23+
'[["type1", {"name":"eric"}, {"name":"larry"}, {"name":"sergey"}]]';
24+
// This matcher is used to match the value used in the `matchHandler` callback
25+
// in tests.
26+
// The `RichRemoteArrayMatcher` takes in the parsed `responseJsonTest`
27+
// above and augments each object within the array with methods that it defines.
28+
// By default mocks do === comparison between the expected and actual value,
29+
// so to avoid copying those method implementations into the test, we instead
30+
// implement a matcher that checks to see that the value given to the callback
31+
// is roughly what we expected it to be: an array whose objects have the names
32+
// listed above.
33+
// Effectively, this is structurally matching the following:
34+
// [{name: 'eric'},{name:'larry'},{name:'sergey'}]
35+
const ignoresRenderAndSelectMatcher = new ArgumentMatcher((arg) => {
36+
if (!Array.isArray(arg)) {
37+
return false;
38+
}
39+
return arg[0].name === 'eric' && arg[1].name === 'larry' &&
40+
arg[2].name === 'sergey';
41+
}, 'matchesType1');
2342

2443
let mockControl;
2544
let mockMatchHandler;
@@ -42,7 +61,7 @@ testSuite({
4261

4362
testRequestMatchingRows() {
4463
const matcher = new RichRemoteArrayMatcher(url);
45-
mockMatchHandler(token, responseJsonType1);
64+
mockMatchHandler(token, ignoresRenderAndSelectMatcher);
4665
mockControl.$replayAll();
4766
matcher.requestMatchingRows(token, maxMatches, mockMatchHandler);
4867
matcher.xhr_.simulateResponse(200, responseJsonText);
@@ -56,7 +75,7 @@ testSuite({
5675
assertEquals('type1', type);
5776
return response;
5877
});
59-
mockMatchHandler(token, responseJsonType1);
78+
mockMatchHandler(token, ignoresRenderAndSelectMatcher);
6079
mockControl.$replayAll();
6180
matcher.requestMatchingRows(token, maxMatches, mockMatchHandler);
6281
matcher.xhr_.simulateResponse(200, responseJsonText);

0 commit comments

Comments
 (0)