Tone.js/test/helper/Basic.ts

55 lines
1.7 KiB
TypeScript
Raw Normal View History

2019-04-12 14:37:47 +00:00
import { expect } from "chai";
2019-07-23 17:12:41 +00:00
import "Tone/core/clock/Transport";
import "Tone/core/context/Destination";
2019-05-23 18:00:49 +00:00
import { OfflineContext } from "Tone/core/context/OfflineContext";
import { ToneWithContext } from "Tone/core/context/ToneWithContext";
import { Tone } from "Tone/core/Tone";
import { ConnectTest } from "./Connect";
2019-04-12 14:37:47 +00:00
2019-05-23 18:00:49 +00:00
export const testAudioContext = new OfflineContext(1, 1, 11025);
2019-06-23 18:59:49 +00:00
testAudioContext.initialize();
2019-04-12 14:37:47 +00:00
// tslint:disable-next-line
2019-05-23 18:00:49 +00:00
export function BasicTests(Constr, ...args: any[]): void {
2019-04-12 14:37:47 +00:00
context("Basic", () => {
it("can be created and disposed", () => {
const instance = new Constr(...args);
instance.dispose();
// check that all of the attributes were disposed
expect(instance.disposed).to.equal(true);
// also check all of it's attributes to see if they also have the right context
for (const member in instance) {
if (instance[member] instanceof Tone && member !== "context") {
expect(instance[member].disposed, `member ${member}`).to.equal(true);
}
}
2019-04-12 14:37:47 +00:00
});
it("extends Tone", () => {
const instance = new Constr(...args);
expect(instance).to.be.an.instanceof(Tone);
instance.dispose();
});
it("can specify the AudioContext", () => {
const instance = new Constr(Object.assign({
context: testAudioContext,
}, ...args));
2019-05-23 18:00:49 +00:00
if (instance instanceof ToneWithContext) {
2019-04-12 14:37:47 +00:00
expect(instance.context).to.equal(testAudioContext);
// also check all of it's attributes to see if they also have the right context
for (const member in instance) {
2019-05-23 18:00:49 +00:00
if (instance[member] instanceof ToneWithContext) {
expect(instance[member].context, `member: ${member}`).to.equal(testAudioContext);
2019-04-12 14:37:47 +00:00
}
}
}
instance.dispose();
});
ConnectTest(Constr, ...args);
2019-04-12 14:37:47 +00:00
});
}