我存根getElementById
,beforeEach
并希望在另一个测试之前恢复它,并再次存根返回另一个值。因为现在我收到错误
TypeError: Attempted to wrap getElementById which is already wrapped
let loginUrl = 'loginUrl'
const url = '/app/auth'
const textContent = `{"${loginUrl}":"${url}"}`
let htmlDecode
describe('identityServer', () => {
beforeEach(() => {
htmlDecode = sinon.stub().returns(textContent)
sinon.stub(document, 'getElementById').returns({textContent})
sinon.stub(htmlEncoder, 'Encoder').returns({htmlDecode: () => htmlDecode})
identityServerModel()
})
it('should return correct model for IdentityServer', () => {
window.identityServer.getModel().should.deep.equal({[loginUrl]: url})
})
})
describe('identityServer', () => {
beforeEach(() => {
htmlDecode = sinon.stub().returns(textContent)
sinon.stub(document, 'getElementById').returns({innerHTML: textContent})
sinon.stub(htmlEncoder, 'Encoder').returns({htmlDecode: () => htmlDecode})
identityServerModel()
})
it('should return correct model using serialization HTML from innerHTML property when textContent is undefined', () => {
window.identityServer.getModel().should.deep.equal({[loginUrl]: url})
})
})