Commit 986595db authored by Luciano Pacheco's avatar Luciano Pacheco Committed by Commit Bot

[Files app] ES6 class for unittest_util.js

Bug: 778674
Change-Id: I26cde7a7d5b606d7e038ae609c460e6434155c2a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1599064
Auto-Submit: Luciano Pacheco <lucmult@chromium.org>
Reviewed-by: default avatarAlex Danilo <adanilo@chromium.org>
Commit-Queue: Luciano Pacheco <lucmult@chromium.org>
Cr-Commit-Position: refs/heads/master@{#658402}
parent 663f0c85
...@@ -52,55 +52,56 @@ function assertFileEntryPathsEqual(expectedPaths, fileEntries) { ...@@ -52,55 +52,56 @@ function assertFileEntryPathsEqual(expectedPaths, fileEntries) {
* recorder.assertCallCount(1); * recorder.assertCallCount(1);
* assertEquals(recorder.getListCall()[0], 'hammy'); * assertEquals(recorder.getListCall()[0], 'hammy');
* </pre> * </pre>
* @constructor
*/ */
function TestCallRecorder() { class TestCallRecorder {
/** @private {!Array<!Arguments>} */ constructor() {
this.calls_ = []; /** @private {!Array<!Arguments>} */
this.calls_ = [];
/**
* The recording function. Bound in our constructor to ensure we always
* return the same object. This is necessary as some clients may make use
* of object equality.
*
* @type {function(*)}
*/
this.callback = this.recordArguments_.bind(this);
}
/** /**
* The recording function. Bound in our constructor to ensure we always * Records the magic {@code arguments} value for later inspection.
* return the same object. This is necessary as some clients may make use * @private
* of object equality.
*
* @type {function(*)}
*/ */
this.callback = this.recordArguments_.bind(this); recordArguments_() {
} this.calls_.push(arguments);
}
/**
* Records the magic {@code arguments} value for later inspection.
* @private
*/
TestCallRecorder.prototype.recordArguments_ = function() {
this.calls_.push(arguments);
};
/** /**
* Asserts that the recorder was called {@code expected} times. * Asserts that the recorder was called {@code expected} times.
* @param {number} expected The expected number of calls. * @param {number} expected The expected number of calls.
*/ */
TestCallRecorder.prototype.assertCallCount = function(expected) { assertCallCount(expected) {
const actual = this.calls_.length; const actual = this.calls_.length;
assertEquals( assertEquals(
expected, actual, expected, actual,
'Expected ' + expected + ' call(s), but was ' + actual + '.'); 'Expected ' + expected + ' call(s), but was ' + actual + '.');
}; }
/** /**
* @return {?Arguments} Returns the {@code Arguments} for the last call, * @return {?Arguments} Returns the {@code Arguments} for the last call,
* or null if the recorder hasn't been called. * or null if the recorder hasn't been called.
*/ */
TestCallRecorder.prototype.getLastArguments = function() { getLastArguments() {
return (this.calls_.length === 0) ? null : return (this.calls_.length === 0) ? null :
this.calls_[this.calls_.length - 1]; this.calls_[this.calls_.length - 1];
}; }
/** /**
* @param {number} index Index of which args to return. * @param {number} index Index of which args to return.
* @return {?Arguments} Returns the {@code Arguments} for the call specified * @return {?Arguments} Returns the {@code Arguments} for the call specified
* by indexd. * by indexd.
*/ */
TestCallRecorder.prototype.getArguments = function(index) { getArguments(index) {
return (index < this.calls_.length) ? this.calls_[index] : null; return (index < this.calls_.length) ? this.calls_[index] : null;
}; }
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment