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

Code before:
  it('does not warn if not enabled', () => {
    create(devtools(() => ({ count: 0 })))
    expect(console.warn).not.toBeCalled()
  })

  it('[DEV-ONLY] warns if enabled in dev mode', () => {
    __DEV__ = true
    create(devtools(() => ({ count: 0 }), { enabled: true }))
    expect(console.warn).toBeCalled()
  })

  it('[PRD-ONLY] does not warn if not in dev env', () => {
    __DEV__ = false
    create(devtools(() => ({ count: 0 })))
    expect(console.warn).not.toBeCalled()
  })

  it('[PRD-ONLY] does not warn if not in dev env even if enabled', () => {
    __DEV__ = false
    create(devtools(() => ({ count: 0 }), { enabled: true }))
    expect(console.warn).not.toBeCalled()
  })
})

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

    api.setState({ count: 10 }, false, 'testSetStateName')
    expect(extension.send).toHaveBeenLastCalledWith(
      { type: 'testSetStateName' },
      { count: 10, foo: 'bar' }
    )

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

    api.setState({ count: 5, foo: 'baz' }, true)
    expect(extension.send).toHaveBeenLastCalledWith(
      { type: 'anonymous' },

Review comment (suggestion):
Nitpick: We can keep this too as it is (the spec is that "it sends `setStateName`" and `setStateName` in turn is `"testSetStateName"` for the given tests, but it can be anything).
```suggestion
  it("sends { type: setStateName || 'anonymous`, ...rest } as the action with current state", () => {
```

Code after:
  it('does not warn if not enabled', () => {
    create(devtools(() => ({ count: 0 })))
    expect(console.warn).not.toBeCalled()
  })

  it('[DEV-ONLY] warns if enabled in dev mode', () => {
    __DEV__ = true
    create(devtools(() => ({ count: 0 }), { enabled: true }))
    expect(console.warn).toBeCalled()
  })

  it('[PRD-ONLY] does not warn if not in dev env', () => {
    __DEV__ = false
    create(devtools(() => ({ count: 0 })))
    expect(console.warn).not.toBeCalled()
  })

  it('[PRD-ONLY] does not warn if not in dev env even if enabled', () => {
    __DEV__ = false
    create(devtools(() => ({ count: 0 }), { enabled: true }))
    expect(console.warn).not.toBeCalled()
  })
})

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

    api.setState({ count: 10 }, false, 'testSetStateName')
    expect(extension.send).toHaveBeenLastCalledWith(
      { type: 'testSetStateName' },
      { count: 10, foo: 'bar' }
    )

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

    api.setState({ count: 5, foo: 'baz' }, true)
    expect(extension.send).toHaveBeenLastCalledWith(
      { type: 'anonymous' },