ChristmasLights.spec.ts 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. import { mount, flushPromises } from "@vue/test-utils";
  2. import { createTestingPinia } from "@pinia/testing";
  3. import ChristmasLights from "@/components/ChristmasLights.vue";
  4. import { useUserAuthStore } from "@/stores/userAuth";
  5. describe("christmas lights component", () => {
  6. test("mount", async () => {
  7. expect(ChristmasLights).toBeTruthy();
  8. const wrapper = mount(ChristmasLights, {
  9. global: {
  10. plugins: [createTestingPinia()]
  11. }
  12. });
  13. expect(wrapper.classes()).toContain("christmas-lights");
  14. expect(wrapper.html()).toMatchSnapshot();
  15. });
  16. test("props", async () => {
  17. expect(ChristmasLights).toBeTruthy();
  18. const wrapper = mount(ChristmasLights, {
  19. global: {
  20. plugins: [createTestingPinia()]
  21. },
  22. props: {
  23. small: false,
  24. lights: 1
  25. }
  26. });
  27. expect(wrapper.classes()).not.toContain("christmas-lights-small");
  28. expect(
  29. wrapper.findAll(".christmas-lights .christmas-wire").length
  30. ).toBe(1 + 1);
  31. expect(
  32. wrapper.findAll(".christmas-lights .christmas-light").length
  33. ).toBe(1);
  34. await wrapper.setProps({
  35. small: true,
  36. lights: 10
  37. });
  38. expect(wrapper.classes()).toContain("christmas-lights-small");
  39. expect(
  40. wrapper.findAll(".christmas-lights .christmas-wire").length
  41. ).toBe(10 + 1);
  42. expect(
  43. wrapper.findAll(".christmas-lights .christmas-light").length
  44. ).toBe(10);
  45. expect(wrapper.html()).toMatchSnapshot();
  46. });
  47. test("loggedIn state", async () => {
  48. expect(ChristmasLights).toBeTruthy();
  49. const wrapper = mount(ChristmasLights, {
  50. global: {
  51. plugins: [createTestingPinia()]
  52. }
  53. });
  54. const userAuthStore = useUserAuthStore();
  55. expect(userAuthStore.loggedIn).toEqual(false);
  56. expect(wrapper.classes()).not.toContain("loggedIn");
  57. userAuthStore.loggedIn = true;
  58. await flushPromises();
  59. expect(userAuthStore.loggedIn).toEqual(true);
  60. expect(wrapper.classes()).toContain("loggedIn");
  61. expect(wrapper.html()).toMatchSnapshot();
  62. });
  63. });