如果不在 beforeEach 中,则 Jest 测试失败

时间:2021-05-11 15:43:16

标签: javascript typescript jestjs ts-jest

我不明白为什么只有当我在 <body> 中设置 beforeEach 时我的测试才能通过?

我想更改每个 <body> 中的 it 但它不起作用。

有什么想法吗?

// ❌ Not working
describe('#nestedForm', () => {
  it('should create new todo', () => {
    startStimulus()

    document.body.innerHTML = `<form data-controller="nested-form"></form>`

    // ...
  })
})

// ✅ Working
describe('#nestedForm', () => {
  beforeEach(() => {
    startStimulus()

    document.body.innerHTML = `<form data-controller="nested-form"></form>`
  })

  it('should create new todo', () => {
    // ...
  })
})

0 个答案:

没有答案