How to stop function execution under test?
P粉348915572
P粉348915572 2024-02-17 14:38:18
0
1
328

How to test this case?

I have a variable in the settings:

setup() {
      const address = `${process.env.VAR_ENV}`
  onMounted(async () => {
        const stop = await isContinuing(address)

When the test is running, the function await isContinuing(address) is executing. How can I make the function not run while the test is running?

My test has undefined wrapper variable

beforeEach(() => {
  wrapper = shallowMount(App, {
  })
})

describe('Dashboard', () => {
  it('test to verify if initial section.', () => {
    const expected = 0
    expect(wrapper.findComponent({ ref: 'section' }).element.value).toBe(
      expected
    )
  })

P粉348915572
P粉348915572

reply all(1)
P粉917406009

Jest (and I assume most testing frameworks) sets the NODE_ENV environment variable to test. So you can use a simple if statement to not do something in your test:

if(process.env.NODE_ENV !== 'test') {
  const stop = await isContinuing(address)
}
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!