Skip to content

Conversation

@philipp-spiess
Copy link
Member

Quick follow-up to #14659 base don @thecrypticace's idea:

  • This behavior is no longer added to the types of the Plugin API to be consistent with v3
  • When the plugin argument is used as a function, we now warn the first time

test('theme keys can read from the CSS theme', () => {
let theme = new Theme()
theme.add('--color-green', 'green')
let originalWarn = console.warn
Copy link
Contributor

@thecrypticace thecrypticace Oct 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd probably just mock console for the entire test file — it'll help cleanup the test and makes adding / testing additional warnings in the future simpler:

  const warn = vi.spyOn(console, 'warn').mockImplementation(() => undefined);

  afterAll(() => warn.mockReset());
    expect(warn).toHaveBeenCalledWith(
       'Using the plugin object parameter as the theme function is deprecated. Please use the `theme` property instead.',
     )

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a fan of mocking apis like this too broadly since it can lead to us hiding warnings somewhere where we don't want it. Can put this test into a describe block to scope this and still use the same pattern though 👍 (or can use the onTestFinished hook to clean up and have it inside the single test only.. 🤔)

let warn = vi.spyOn(console, 'warn').mockImplementation(() => undefined)
onTestFinished(() => {
warn.mockReset()
})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ooh I forgot this existed 💯

@philipp-spiess philipp-spiess merged commit a64e209 into next Oct 14, 2024
@philipp-spiess philipp-spiess deleted the chore/warn-on-use-of-plugin-parameter-as-fn branch October 14, 2024 11:57
philipp-spiess added a commit that referenced this pull request Oct 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants