---
source: crates/oxc_linter/src/tester.rs
expression: no_conditional_expect
---
  ⚠ eslint(jest/no-conditional-expect): Unexpected conditional expect
   ╭─[no_conditional_expect.tsx:2:1]
 2 │                 it('foo', () => {
 3 │                     something && expect(something).toHaveBeenCalled();
   ·                                  ────────────────────────────────────
 4 │                 })
   ╰────
  help: Avoid calling `expect` conditionally`

  ⚠ eslint(jest/no-conditional-expect): Unexpected conditional expect
   ╭─[no_conditional_expect.tsx:2:1]
 2 │                 it('foo', () => {
 3 │                     a || b && expect(something).toHaveBeenCalled();
   ·                               ────────────────────────────────────
 4 │                 })
   ╰────
  help: Avoid calling `expect` conditionally`

  ⚠ eslint(jest/no-conditional-expect): Unexpected conditional expect
   ╭─[no_conditional_expect.tsx:2:1]
 2 │                 it('foo', () => {
 3 │                     (a || b) && expect(something).toHaveBeenCalled();
   ·                                 ────────────────────────────────────
 4 │                 })
   ╰────
  help: Avoid calling `expect` conditionally`

  ⚠ eslint(jest/no-conditional-expect): Unexpected conditional expect
   ╭─[no_conditional_expect.tsx:2:1]
 2 │                 it('foo', () => {
 3 │                     a || (b && expect(something).toHaveBeenCalled());
   ·                                ────────────────────────────────────
 4 │                 })
   ╰────
  help: Avoid calling `expect` conditionally`

  ⚠ eslint(jest/no-conditional-expect): Unexpected conditional expect
   ╭─[no_conditional_expect.tsx:2:1]
 2 │                 it('foo', () => {
 3 │                     a && b && expect(something).toHaveBeenCalled();
   ·                               ────────────────────────────────────
 4 │                 })
   ╰────
  help: Avoid calling `expect` conditionally`

  ⚠ eslint(jest/no-conditional-expect): Unexpected conditional expect
   ╭─[no_conditional_expect.tsx:2:1]
 2 │                 it('foo', () => {
 3 │                     a && b || expect(something).toHaveBeenCalled();
   ·                               ────────────────────────────────────
 4 │                 })
   ╰────
  help: Avoid calling `expect` conditionally`

  ⚠ eslint(jest/no-conditional-expect): Unexpected conditional expect
   ╭─[no_conditional_expect.tsx:2:1]
 2 │                 it('foo', () => {
 3 │                     (a && b) || expect(something).toHaveBeenCalled();
   ·                                 ────────────────────────────────────
 4 │                 })
   ╰────
  help: Avoid calling `expect` conditionally`

  ⚠ eslint(jest/no-conditional-expect): Unexpected conditional expect
   ╭─[no_conditional_expect.tsx:2:1]
 2 │                 function getValue() {
 3 │                     something && expect(something).toHaveBeenCalled(); 
   ·                                  ────────────────────────────────────
 4 │                 }
   ╰────
  help: Avoid calling `expect` conditionally`

  ⚠ eslint(jest/no-conditional-expect): Unexpected conditional expect
   ╭─[no_conditional_expect.tsx:2:1]
 2 │                 it('foo', () => {
 3 │                     something || expect(something).toHaveBeenCalled();
   ·                                  ────────────────────────────────────
 4 │                 })
   ╰────
  help: Avoid calling `expect` conditionally`

  ⚠ eslint(jest/no-conditional-expect): Unexpected conditional expect
   ╭─[no_conditional_expect.tsx:2:1]
 2 │                 it.each``('foo', () => {
 3 │                     something || expect(something).toHaveBeenCalled();
   ·                                  ────────────────────────────────────
 4 │                 })
   ╰────
  help: Avoid calling `expect` conditionally`

  ⚠ eslint(jest/no-conditional-expect): Unexpected conditional expect
   ╭─[no_conditional_expect.tsx:2:1]
 2 │                 it.each()('foo', () => {
 3 │                     something || expect(something).toHaveBeenCalled();
   ·                                  ────────────────────────────────────
 4 │                 })
   ╰────
  help: Avoid calling `expect` conditionally`

  ⚠ eslint(jest/no-conditional-expect): Unexpected conditional expect
   ╭─[no_conditional_expect.tsx:2:1]
 2 │                 function getValue() {
 3 │                     something || expect(something).toHaveBeenCalled(); 
   ·                                  ────────────────────────────────────
 4 │                 }
   ╰────
  help: Avoid calling `expect` conditionally`

  ⚠ eslint(jest/no-conditional-expect): Unexpected conditional expect
   ╭─[no_conditional_expect.tsx:2:1]
 2 │                 it('foo', () => {
 3 │                     something ? expect(something).toHaveBeenCalled() : noop();
   ·                                 ────────────────────────────────────
 4 │                 })
   ╰────
  help: Avoid calling `expect` conditionally`

  ⚠ eslint(jest/no-conditional-expect): Unexpected conditional expect
   ╭─[no_conditional_expect.tsx:2:1]
 2 │                 function getValue() {
 3 │                     something ? expect(something).toHaveBeenCalled() : noop();
   ·                                 ────────────────────────────────────
 4 │                 }
   ╰────
  help: Avoid calling `expect` conditionally`

  ⚠ eslint(jest/no-conditional-expect): Unexpected conditional expect
   ╭─[no_conditional_expect.tsx:2:1]
 2 │                 it('foo', () => {
 3 │                     something ? noop() : expect(something).toHaveBeenCalled();
   ·                                          ────────────────────────────────────
 4 │                 })
   ╰────
  help: Avoid calling `expect` conditionally`

  ⚠ eslint(jest/no-conditional-expect): Unexpected conditional expect
   ╭─[no_conditional_expect.tsx:2:1]
 2 │                 it.each``('foo', () => {
 3 │                     something ? noop() : expect(something).toHaveBeenCalled();
   ·                                          ────────────────────────────────────
 4 │                 })
   ╰────
  help: Avoid calling `expect` conditionally`

  ⚠ eslint(jest/no-conditional-expect): Unexpected conditional expect
   ╭─[no_conditional_expect.tsx:2:1]
 2 │                 it.each()('foo', () => {
 3 │                     something ? noop() : expect(something).toHaveBeenCalled();
   ·                                          ────────────────────────────────────
 4 │                 })
   ╰────
  help: Avoid calling `expect` conditionally`

  ⚠ eslint(jest/no-conditional-expect): Unexpected conditional expect
   ╭─[no_conditional_expect.tsx:2:1]
 2 │                 function getValue() {
 3 │                     something ? noop() : expect(something).toHaveBeenCalled();
   ·                                          ────────────────────────────────────
 4 │                 }
   ╰────
  help: Avoid calling `expect` conditionally`

  ⚠ eslint(jest/no-conditional-expect): Unexpected conditional expect
   ╭─[no_conditional_expect.tsx:6:1]
 6 │                     default:
 7 │                         expect(something).toHaveBeenCalled();
   ·                         ────────────────────────────────────
 8 │                     }
   ╰────
  help: Avoid calling `expect` conditionally`

  ⚠ eslint(jest/no-conditional-expect): Unexpected conditional expect
   ╭─[no_conditional_expect.tsx:4:1]
 4 │                     case 'value':
 5 │                         expect(something).toHaveBeenCalled();
   ·                         ────────────────────────────────────
 6 │                     default:
   ╰────
  help: Avoid calling `expect` conditionally`

  ⚠ eslint(jest/no-conditional-expect): Unexpected conditional expect
   ╭─[no_conditional_expect.tsx:4:1]
 4 │                     case 'value':
 5 │                         expect(something).toHaveBeenCalled();
   ·                         ────────────────────────────────────
 6 │                     default:
   ╰────
  help: Avoid calling `expect` conditionally`

  ⚠ eslint(jest/no-conditional-expect): Unexpected conditional expect
   ╭─[no_conditional_expect.tsx:4:1]
 4 │                     case 'value':
 5 │                         expect(something).toHaveBeenCalled();
   ·                         ────────────────────────────────────
 6 │                     default:
   ╰────
  help: Avoid calling `expect` conditionally`

  ⚠ eslint(jest/no-conditional-expect): Unexpected conditional expect
   ╭─[no_conditional_expect.tsx:6:1]
 6 │                     default:
 7 │                         expect(something).toHaveBeenCalled();
   ·                         ────────────────────────────────────
 8 │                     }
   ╰────
  help: Avoid calling `expect` conditionally`

  ⚠ eslint(jest/no-conditional-expect): Unexpected conditional expect
   ╭─[no_conditional_expect.tsx:3:1]
 3 │                     if(doSomething) {
 4 │                         expect(something).toHaveBeenCalled();
   ·                         ────────────────────────────────────
 5 │                     }
   ╰────
  help: Avoid calling `expect` conditionally`

  ⚠ eslint(jest/no-conditional-expect): Unexpected conditional expect
   ╭─[no_conditional_expect.tsx:5:1]
 5 │                     } else {
 6 │                         expect(something).toHaveBeenCalled();
   ·                         ────────────────────────────────────
 7 │                     }
   ╰────
  help: Avoid calling `expect` conditionally`

  ⚠ eslint(jest/no-conditional-expect): Unexpected conditional expect
   ╭─[no_conditional_expect.tsx:5:1]
 5 │                     } else {
 6 │                         expect(something).toHaveBeenCalled();
   ·                         ────────────────────────────────────
 7 │                     }
   ╰────
  help: Avoid calling `expect` conditionally`

  ⚠ eslint(jest/no-conditional-expect): Unexpected conditional expect
   ╭─[no_conditional_expect.tsx:5:1]
 5 │                     } else {
 6 │                         expect(something).toHaveBeenCalled();
   ·                         ────────────────────────────────────
 7 │                     }
   ╰────
  help: Avoid calling `expect` conditionally`

  ⚠ eslint(jest/no-conditional-expect): Unexpected conditional expect
   ╭─[no_conditional_expect.tsx:3:1]
 3 │                     if(doSomething) {
 4 │                         expect(something).toHaveBeenCalled();
   ·                         ────────────────────────────────────
 5 │                     }
   ╰────
  help: Avoid calling `expect` conditionally`

  ⚠ eslint(jest/no-conditional-expect): Unexpected conditional expect
   ╭─[no_conditional_expect.tsx:5:1]
 5 │                     } else {
 6 │                     expect(something).toHaveBeenCalled();
   ·                     ────────────────────────────────────
 7 │                     }
   ╰────
  help: Avoid calling `expect` conditionally`

  ⚠ eslint(jest/no-conditional-expect): Unexpected conditional expect
   ╭─[no_conditional_expect.tsx:5:1]
 5 │                     } catch (err) {
 6 │                     expect(err).toMatch('Error');
   ·                     ────────────────────────────
 7 │                     }
   ╰────
  help: Avoid calling `expect` conditionally`

  ⚠ eslint(jest/no-conditional-expect): Unexpected conditional expect
   ╭─[no_conditional_expect.tsx:5:1]
 5 │                     } catch (err) {
 6 │                     expect(err).toMatch('Error');
   ·                     ────────────────────────────
 7 │                     }
   ╰────
  help: Avoid calling `expect` conditionally`

  ⚠ eslint(jest/no-conditional-expect): Unexpected conditional expect
   ╭─[no_conditional_expect.tsx:5:1]
 5 │                     } catch (err) {
 6 │                         expect(err).toMatch('Error');
   ·                         ────────────────────────────
 7 │                     }
   ╰────
  help: Avoid calling `expect` conditionally`

  ⚠ eslint(jest/no-conditional-expect): Unexpected conditional expect
   ╭─[no_conditional_expect.tsx:5:1]
 5 │                     } catch (err) {
 6 │                         expect(err).toMatch('Error');
   ·                         ────────────────────────────
 7 │                     }
   ╰────
  help: Avoid calling `expect` conditionally`

  ⚠ eslint(jest/no-conditional-expect): Unexpected conditional expect
   ╭─[no_conditional_expect.tsx:5:1]
 5 │                     } catch (err) {
 6 │                         expect(err).toMatch('Error');
   ·                         ────────────────────────────
 7 │                     }
   ╰────
  help: Avoid calling `expect` conditionally`

  ⚠ eslint(jest/no-conditional-expect): Unexpected conditional expect
   ╭─[no_conditional_expect.tsx:5:1]
 5 │                     } catch {
 6 │                     expect(something).toHaveBeenCalled();
   ·                     ────────────────────────────────────
 7 │                     }
   ╰────
  help: Avoid calling `expect` conditionally`

  ⚠ eslint(jest/no-conditional-expect): Unexpected conditional expect
   ╭─[no_conditional_expect.tsx:4:1]
 4 │                     .then(() => { throw new Error('oh noes!'); })
 5 │                     .catch(error => expect(error).toBeInstanceOf(Error));
   ·                                     ───────────────────────────────────
 6 │                 });
   ╰────
  help: Avoid calling `expect` conditionally`

  ⚠ eslint(jest/no-conditional-expect): Unexpected conditional expect
    ╭─[no_conditional_expect.tsx:8:1]
  8 │                     .then(() => { throw new Error('oh noes!'); })
  9 │                     .catch(error => expect(error).toBeInstanceOf(Error));
    ·                                     ───────────────────────────────────
 10 │                 });
    ╰────
  help: Avoid calling `expect` conditionally`

  ⚠ eslint(jest/no-conditional-expect): Unexpected conditional expect
   ╭─[no_conditional_expect.tsx:6:1]
 6 │                     .then(() => { throw new Error('oh noes!'); })
 7 │                     .catch(error => expect(error).toBeInstanceOf(Error))
   ·                                     ───────────────────────────────────
 8 │                     .then(() => { throw new Error('oh noes!'); })
   ╰────
  help: Avoid calling `expect` conditionally`

  ⚠ eslint(jest/no-conditional-expect): Unexpected conditional expect
   ╭─[no_conditional_expect.tsx:4:1]
 4 │                     .then(() => { throw new Error('oh noes!'); })
 5 │                     .catch(error => expect(error).toBeInstanceOf(Error))
   ·                                     ───────────────────────────────────
 6 │                     .then(() => { throw new Error('oh noes!'); })
   ╰────
  help: Avoid calling `expect` conditionally`

  ⚠ eslint(jest/no-conditional-expect): Unexpected conditional expect
   ╭─[no_conditional_expect.tsx:5:1]
 5 │                         .catch(error => expect(error).toBeInstanceOf(Error))
 6 │                         .catch(error => expect(error).toBeInstanceOf(Error));
   ·                                         ───────────────────────────────────
 7 │                     });
   ╰────
  help: Avoid calling `expect` conditionally`

  ⚠ eslint(jest/no-conditional-expect): Unexpected conditional expect
   ╭─[no_conditional_expect.tsx:4:1]
 4 │                         .catch(error => expect(error).toBeInstanceOf(Error))
 5 │                         .catch(error => expect(error).toBeInstanceOf(Error))
   ·                                         ───────────────────────────────────
 6 │                         .catch(error => expect(error).toBeInstanceOf(Error));
   ╰────
  help: Avoid calling `expect` conditionally`

  ⚠ eslint(jest/no-conditional-expect): Unexpected conditional expect
   ╭─[no_conditional_expect.tsx:3:1]
 3 │                       await Promise.resolve()
 4 │                         .catch(error => expect(error).toBeInstanceOf(Error))
   ·                                         ───────────────────────────────────
 5 │                         .catch(error => expect(error).toBeInstanceOf(Error))
   ╰────
  help: Avoid calling `expect` conditionally`

  ⚠ eslint(jest/no-conditional-expect): Unexpected conditional expect
   ╭─[no_conditional_expect.tsx:3:1]
 3 │                     await Promise.resolve()
 4 │                     .catch(error => expect(error).toBeInstanceOf(Error))
   ·                                     ───────────────────────────────────
 5 │                     .then(() => { throw new Error('oh noes!'); })
   ╰────
  help: Avoid calling `expect` conditionally`

  ⚠ eslint(jest/no-conditional-expect): Unexpected conditional expect
   ╭─[no_conditional_expect.tsx:4:1]
 4 │                     .then(() => { throw new Error('oh noes!'); })
 5 │                     .catch(error => expect(error).toBeInstanceOf(Error));
   ·                                     ───────────────────────────────────
 6 │                 });
   ╰────
  help: Avoid calling `expect` conditionally`

  ⚠ eslint(jest/no-conditional-expect): Unexpected conditional expect
   ╭─[no_conditional_expect.tsx:2:1]
 2 │                 it('works', async () => {
 3 │                     await somePromise.catch(error => expect(error).toBeInstanceOf(Error));
   ·                                                      ───────────────────────────────────
 4 │                 });
   ╰────
  help: Avoid calling `expect` conditionally`


