テスト駆動開発
Last updated
Last updated
import Synth from '/src/Synth'
const synth = new Synth()
// 再生時に期待する動き
describe('play', () => {
const options = {
midiNoteNumber: 70,
}
it('state', () => {
// midiNoteNumber 70 で再生する
synth.play(options)
// state には今の状態が記録されている
const state = synth.oscillatorArray[options.midiNoteNumber].state
const expectedState = {
play: true,
midiNoteNumber: 70,
}
// state が上記のような状態になることを期待
expect(state).toEqual(expectedState)
})
it('osc', () => {
// 実際のオシレーターノードが保存されている場所
const osc = synth.oscillatorArray[options.midiNoteNumber].osc
// オシレーターノードが、存在することを期待
expect(!!osc).toBe(true)
})
})
// 停止時に期待する動き
describe('stop', () => {
const options = {
midiNoteNumber: 70,
}
it('state', () => {
// midiNoteNumber 70 を停止する
synth.stop(options)
const state = synth.oscillatorArray[options.midiNoteNumber].state
const expectedState = {
play: false,
midiNoteNumber: null,
}
expect(state).toEqual(expectedState)
})
it('osc', () => {
const osc = synth.oscillatorArray[options.midiNoteNumber].osc
// オシレーターは破棄され存在しないことを期待
expect(!!osc).toBe(false)
})
})
// すでに停止している音を停止させる時の挙動
describe('double stop', () => {
const options = {
midiNoteNumber: 70,
}
it('state', () => {
// midiNoteNumber 70 を停止する
synth.stop(options)
const state = synth.oscillatorArray[options.midiNoteNumber].state
const expectedState = {
play: false,
midiNoteNumber: null,
}
expect(state).toEqual(expectedState)
})
it('osc', () => {
const osc = synth.oscillatorArray[options.midiNoteNumber].osc
// オシレーターは破棄され存在しないことを期待
expect(!!osc).toBe(false)
})
})