如果测试共享并改变某些公共状态,并且其逻辑取决于先前的测试,该怎么办?这是可以接受的做法吗? 例如简单的代码(js):
describe('Some tests', () => {
const state = {
value: 'test'
addMe() {
this.value = this.value + ' me'
}
addPlease() {
this.value = this.value + ', please'
}
}
it('Some test', () => {
state.addMe()
expect(state.value).toBe('test me')
})
it('Another test', () => {
state.addPlease()
expect(state.value).toBe('test me, please')
})
})