0

でスタブgetElementByIdbeforeEach、別のテストの前にそれを復元し、別の戻り値で再度スタブしたいと考えています。今私はエラーを受け取るので 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})
        })
    })
4

1 に答える 1