scratch-audio/test/__mocks__/AudioNode.js
2018-06-08 12:39:29 -04:00

36 lines
858 B
JavaScript

class AudioNodeMock {
constructor (params) {
Object.assign(this, params);
this.connected = null;
this.connectedFrom = [];
this._testResult = [];
}
connect (node) {
this.connected = node;
node.connectedFrom.push(this);
}
disconnect () {
if (this.connected !== null) {
this.connectedFrom = this.connectedFrom.filter(connection => connection !== this);
}
this.connected = null;
}
_test (test, message, depth = 0) {
if (this.connected === null) {
this._testResult.push({test, message, depth});
} else {
this.connected._test(test, message, depth + 1);
this._testResult.push(null);
}
}
_result () {
return this._testResult.pop();
}
}
module.exports = AudioNodeMock;