Tone.js/test/helper/MonophonicTests.ts
Yotam Mann 3c81958cec Adding monophonic tests
checks for onsilence
2019-08-12 00:14:59 -04:00

35 lines
1 KiB
TypeScript

import { expect } from "chai";
import { Offline } from "test/helper/Offline";
import { Monophonic } from "Tone/instrument/Monophonic";
// tslint:disable-next-line
export function MonophonicTest(Constr, note, constrArg?): void {
context("Monophonic Tests", () => {
it ("has an onsilence callback which is invoked after the release has finished", () => {
let wasInvoked = false;
return Offline(() => {
const instance = new Constr(constrArg);
instance.toDestination();
instance.triggerAttackRelease(note, 0.1, 0);
instance.onsilence = () => wasInvoked = true;
}, 2).then(() => {
expect(wasInvoked).to.equal(true);
});
});
it ("invokes onsilence callback when the sustain is set to 0", () => {
let wasInvoked = false;
return Offline(() => {
const instance = new Constr(constrArg);
instance.toDestination();
instance.envelope.sustain = 0;
instance.triggerAttack(note, 0);
instance.onsilence = () => wasInvoked = true;
}, 2).then(() => {
expect(wasInvoked).to.equal(true);
});
});
});
}