Repository: pmndrs/zustand
File: tests/devtools.test.tsx (TypeScript)

Code before:
  const initialState = { count: 0 }
  createStore(devtools(() => initialState, { enabled: true, ...options }))

  expect(extensionConnector.connect).toHaveBeenLastCalledWith(options)

  const [conn] = getNamedConnectionApis(options.name)
  expect(conn.init).toHaveBeenLastCalledWith(initialState)
})

describe('If there is no extension installed...', () => {
  let savedConsoleWarn: any
  beforeEach(() => {
    savedConsoleWarn = console.warn
    console.warn = vi.fn()
    ;(window as any).__REDUX_DEVTOOLS_EXTENSION__ = undefined
  })
  afterEach(() => {
    console.warn = savedConsoleWarn
    ;(window as any).__REDUX_DEVTOOLS_EXTENSION__ = extensionConnector
  })

  it('does not throw', async () => {
    expect(() => {
      createStore(devtools(() => ({ count: 0 })))
    }).not.toThrow()
  })
})

describe('When state changes...', () => {
  it("sends { type: setStateName || 'anonymous`, ...rest } as the action with current state", async () => {
    const options = {
      name: 'testOptionsName',
      enabled: true,
    }
    const api = createStore(devtools(() => ({ count: 0, foo: 'bar' }), options))

    api.setState({ count: 10 }, false, 'testSetStateName')
    const [connection] = getNamedConnectionApis(options.name)
    expect(connection.send).toHaveBeenLastCalledWith(
      { type: 'testSetStateName' },
      { count: 10, foo: 'bar' },
    )

    api.setState({ count: 15 }, false, {
      type: 'testSetStateName',
      payload: 15,
    })
    expect(connection.send).toHaveBeenLastCalledWith(
      { type: 'testSetStateName', payload: 15 },
      { count: 15, foo: 'bar' },
    )

Review comment (suggestion):
I mean the test itself is fine.

```suggestion
  })
  
    it('does not warn', async () => {
    createStore(devtools(() => ({ count: 0 })))
    expect(console.warn).not.toBeCalled()
  })
```

Code after:
  const initialState = { count: 0 }
  createStore(devtools(() => initialState, { enabled: true, ...options }))

  expect(extensionConnector.connect).toHaveBeenLastCalledWith(options)

  const [conn] = getNamedConnectionApis(options.name)
  expect(conn.init).toHaveBeenLastCalledWith(initialState)
})

describe('If there is no extension installed...', () => {
  let savedConsoleWarn: any
  beforeEach(() => {
    savedConsoleWarn = console.warn
    console.warn = vi.fn()
    ;(window as any).__REDUX_DEVTOOLS_EXTENSION__ = undefined
  })
  afterEach(() => {
    console.warn = savedConsoleWarn
    ;(window as any).__REDUX_DEVTOOLS_EXTENSION__ = extensionConnector
  })

  it('does not throw', async () => {
    expect(() => {
      createStore(devtools(() => ({ count: 0 })))
    }).not.toThrow()
  })

  it('does not warn', async () => {
    createStore(devtools(() => ({ count: 0 })))
    expect(console.warn).not.toBeCalled()
  })
})

describe('When state changes...', () => {
  it("sends { type: setStateName || 'anonymous`, ...rest } as the action with current state", async () => {
    const options = {
      name: 'testOptionsName',
      enabled: true,
    }
    const api = createStore(devtools(() => ({ count: 0, foo: 'bar' }), options))

    api.setState({ count: 10 }, false, 'testSetStateName')
    const [connection] = getNamedConnectionApis(options.name)
    expect(connection.send).toHaveBeenLastCalledWith(
      { type: 'testSetStateName' },
      { count: 10, foo: 'bar' },
    )

    api.setState({ count: 15 }, false, {
      type: 'testSetStateName',
      payload: 15,