warnings.test.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. import { html, run, css } from './util/run'
  2. let warn
  3. beforeEach(() => {
  4. let log = require('../src/util/log')
  5. warn = jest.spyOn(log.default, 'warn')
  6. })
  7. afterEach(() => {
  8. warn.mockClear()
  9. })
  10. test('it warns when there is no content key', async () => {
  11. let config = {
  12. corePlugins: { preflight: false },
  13. }
  14. let input = css`
  15. @tailwind base;
  16. `
  17. await run(input, config)
  18. expect(warn).toHaveBeenCalledTimes(1)
  19. expect(warn.mock.calls.map((x) => x[0])).toEqual(['content-problems'])
  20. })
  21. test('it warns when there is an empty content key', async () => {
  22. let config = {
  23. content: [],
  24. corePlugins: { preflight: false },
  25. }
  26. let input = css`
  27. @tailwind base;
  28. `
  29. await run(input, config)
  30. expect(warn).toHaveBeenCalledTimes(1)
  31. expect(warn.mock.calls.map((x) => x[0])).toEqual(['content-problems'])
  32. })
  33. test('it warns when there are no utilities generated', async () => {
  34. let config = {
  35. content: [{ raw: html`nothing here matching a utility` }],
  36. corePlugins: { preflight: false },
  37. }
  38. let input = css`
  39. @tailwind utilities;
  40. `
  41. await run(input, config)
  42. expect(warn).toHaveBeenCalledTimes(1)
  43. expect(warn.mock.calls.map((x) => x[0])).toEqual(['content-problems'])
  44. })
  45. it('warnings are not thrown when only variant utilities are generated', async () => {
  46. let config = {
  47. content: [{ raw: html`<div class="sm:underline"></div>` }],
  48. corePlugins: { preflight: false },
  49. }
  50. let input = css`
  51. @tailwind utilities;
  52. `
  53. await run(input, config)
  54. expect(warn).toHaveBeenCalledTimes(0)
  55. })