最近私のプロジェクトでスピーチにテキストを実装しようとしましたが、プレーンなjavascriptソリューションを利用することに決めました。 (https://developer.mozilla.org/en-US/docs/Web/API/SpeechSynthesisUtterance)テストの失敗:ReferenceError:SpeechSynthesisUtteranceが定義されていません
私は現在[email protected]と[email protected]を使用しています。
コード:
export default class DummyComponent extends React.Component {
/* */
speak(text) {
var synth = window.speechSynthesis;
var utterThis = new SpeechSynthesisUtterance(text);
synth.speak(utterThis);
}
/* */
}
すべてが正常に動作しますが、私は自分のコードをテストしようとするたびに私はタイトルにエラーが発生します。
ExampleTest:
it('dummytest', function(done){
const prop1 = 'foo';
const prop2 = 'bar';
const wrapper = shallow(<DummyComponent prop1 = {foo} prop2={bar}/>);
expect(wrapper.html()).to.include("foobar");
done();
});
ReferenceError: SpeechSynthesisUtterance is not defined
このコンポーネントのすべての私のテストは、酵素法浅く、マウントしてくださいレンダリングという事実に、失敗している私は、このクラスでテストするかは重要ではありませんわからないSpeechSynthesisUtterance。
SpeechSynthesisUtteranceは実際にはtypescript libに由来します。私はすでに試した
物事 (typescriptです/ libに/ lib.es6.d.ts):
- 3.2(まったく同じエラーで利回り)
- に酵素をアップグレードする機能
- を輸出tsconfigファイルを使用してlib.es6.d.tsをコンパイルする
後者では、さまざまな設定を試して、ファイルの先頭に「export {}」を追加してみました。これは実際にこのエラーを投げた:
node_modules/typescript/lib/lib.es6.d.ts(5769,15): error TS2470: 'Symbol' reference does not refer to the global Symbol constructor object.
私はtypescriptでの経験がないので、次に何を試してみるべきか考えていません。機能は、ブラウザでグローバルです(ChromeとFirefoxのを確認してください)ので、あなたはそれを参照する可能性があるため、
ありがとうございます!あなたの提案のおかげで、私はproxyquireとこのblog Postというnpmパッケージを見つけました:https://engineering.thetrainline.com/use-proxyquire-to-mock-your-react-components-2b1e90ee2bac。 – kugtas