我正在尝试对 js-cookie 进行单元测试我的代码是这样的
import Cookie from 'js-cookie'
onChange (e) {
Cookie.set('locale', e.target.value)
window.location.reload()
}
对于单元测试,我正在这样做
describe('LocaleDropDown', () => {
const handleLocaleChange = sinon.spy()
const Cookie = sinon.spy(Cookie,'set')
it("when simulating a change, Cookie.set should be called", () => {
const wrapper = shallow(<LocaleDropDown onChange = {handleLocaleChange}/>)
wrapper.find('select').simulate('change', { target: { value: 'en'}})
expect(Cookie.set.calledOnce).toBe(true)
});
})
它失败说 ReferenceError: Cookie is not defined
我应该如何测试 js-cookie