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) {
* recorder.assertCallCount(1);
* assertEquals(recorder.getListCall()[0], 'hammy');
* </pre>
* @constructor
*/
function TestCallRecorder() {
/** @private {!Array<!Arguments>} */
this.calls_ = [];
class TestCallRecorder {
constructor() {
/** @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
* return the same object. This is necessary as some clients may make use
* of object equality.
*
* @type {function(*)}
* Records the magic {@code arguments} value for later inspection.
* @private
*/
this.callback = this.recordArguments_.bind(this);
}
/**
* Records the magic {@code arguments} value for later inspection.
* @private
*/
TestCallRecorder.prototype.recordArguments_ = function() {
this.calls_.push(arguments);
};
recordArguments_() {
this.calls_.push(arguments);
}
/**
* Asserts that the recorder was called {@code expected} times.
* @param {number} expected The expected number of calls.
*/
TestCallRecorder.prototype.assertCallCount = function(expected) {
const actual = this.calls_.length;
assertEquals(
expected, actual,
'Expected ' + expected + ' call(s), but was ' + actual + '.');
};
/**
* Asserts that the recorder was called {@code expected} times.
* @param {number} expected The expected number of calls.
*/
assertCallCount(expected) {
const actual = this.calls_.length;
assertEquals(
expected, actual,
'Expected ' + expected + ' call(s), but was ' + actual + '.');
}
/**
* @return {?Arguments} Returns the {@code Arguments} for the last call,
* or null if the recorder hasn't been called.
*/
TestCallRecorder.prototype.getLastArguments = function() {
return (this.calls_.length === 0) ? null :
this.calls_[this.calls_.length - 1];
};
/**
* @return {?Arguments} Returns the {@code Arguments} for the last call,
* or null if the recorder hasn't been called.
*/
getLastArguments() {
return (this.calls_.length === 0) ? null :
this.calls_[this.calls_.length - 1];
}
/**
* @param {number} index Index of which args to return.
* @return {?Arguments} Returns the {@code Arguments} for the call specified
* by indexd.
*/
TestCallRecorder.prototype.getArguments = function(index) {
return (index < this.calls_.length) ? this.calls_[index] : null;
};
/**
* @param {number} index Index of which args to return.
* @return {?Arguments} Returns the {@code Arguments} for the call specified
* by indexd.
*/
getArguments(index) {
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