Tone.js/test/helper/Basic.ts

42 lines
1.1 KiB
TypeScript
Raw Normal View History

2019-04-12 14:37:47 +00:00
import { expect } from "chai";
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";
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-04-12 14:37:47 +00:00
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();
});
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) {
2019-04-12 14:37:47 +00:00
expect(instance[member].context).to.equal(testAudioContext);
}
}
}
instance.dispose();
});
});
}