Skip to content

Latest commit

 

History

History
73 lines (54 loc) · 1.12 KB

File metadata and controls

73 lines (54 loc) · 1.12 KB

vitest/hoisted-apis-on-top

📝 Enforce hoisted APIs to be on top of the file.

⚠️ This rule warns in the 🌐 all config.

💡 This rule is manually fixable by editor suggestions.

Rule Details

This rule disallows using APIs which are hoisted by vitest in positions where they look like runtime code.

Examples of incorrect code for this rule:

if (condition) {
  vi.mock('some-module', () => {})
}
if (condition) {
  vi.unmock('some-module', () => {})
}
if (condition) {
  vi.hoisted(() => {})
}
describe('suite', () => {
  it('test', async () => {
    vi.mock('some-module', () => {})

    const sm = await import('some-module')
    // ...
  })
})

Examples of correct code for this rule:

vi.mock('some-module', () => {})

describe('suite', () => {
  it('test', async () => {
    const sm = await import('some-module')
    // ...
  })
})
vi.unmock(() => {})

if (condition) {
  // ...
}
vi.hoisted(() => {})

if (condition) {
  // ...
}