Git Product home page Git Product logo

Comments (2)

mpeyper avatar mpeyper commented on May 31, 2024 1

Hi @max-l,

It looks like you may be falling into one of the only arguments I agree with for using semicolons (;) in javascript:

test('useEmailAddressState', done => {
  const {result} = renderHook(() => useEmailAddressState())
  let [email, isInvalid, setEmail] = result.current
  expect(email).toEqual('')
  act(() => {
    setEmail("pwerofw0")
  }) // no ; here makes the next line part of this line
  [email, isInvalid, setEmail] = result.current
  expect(isInvalid).toEqual(true)
  done()
})

It's like having that line read:

act(() => {
  setEmail("pwerofw0")
})[email, isInvalid, setEmail] = result.current // not what you want

The annoying part is that javascript is more than happy to let that line run without any issues or warnings (but how was is supposed to know you didn't want to do that?).

Anyway, stick a semicolon in and the test will pass

You can write the test as:

test('useEmailAddressState', done => {
  const {result} = renderHook(() => useEmailAddressState())
  let [email, isInvalid, setEmail] = result.current
  expect(email).toEqual('')
  act(() => {
    setEmail("pwerofw0")
  });
  [email, isInvalid, setEmail] = result.current
  expect(isInvalid).toEqual(true)
  done()
})

from react-hooks-testing-library.

max-l avatar max-l commented on May 31, 2024

Wow... that's a bummer, I have been living happily without semicolons for years and never bee bitten,
until now... !

Thanks for the quick response !

from react-hooks-testing-library.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.