Tag:

testing失败:ReferenceError:SpeechSynthesisUtterance未定义

我最近试图在我的项目中实现文本到Speech,并决定使用纯javascript的解决scheme。 ( https://developer.mozilla.org/en-US/docs/Web/API/SpeechSynthesisUtterance ) 我目前使用React@15.4.2和enzyme@2.9.1。 码: export default class DummyComponent extends React.Component { /* */ speak(text) { var synth = window.speechSynthesis; var utterThis = new SpeechSynthesisUtterance(text); synth.speak(utterThis); } /* */ } 一切工作正常,但每当我尝试testing我的代码,我得到的标题中的错误。 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未定义 […]

酶如果React组件需要jQuery,则会引发错误

我试图用Enzyme的describeWithDOM()和mount()来testing一个React组件的行为。 但是,当组件导入jQuery我得到这个错误: 错误:jQuery需要一个包含文档的窗口 我知道Enzyme使用引擎盖下的jsdom,我一直以为jsdom照顾窗口和文件。 但我似乎无法find如何让这些工作在一起。 testing代码如下所示: import chai, {expect} from 'chai'; import Select from './Select'; import React, {createElement} from 'react'; import {describeWithDOM, mount} from 'enzyme'; describe('UI Select', () => { //more shallow tests here describeWithDOM('User Actions', () => { it('Toggles the .ui-options menu on button click', () => { const wrapper = mount(<Select {…baseProps} />); […]