ChristmasLights.spec.ts 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import { flushPromises } from "@vue/test-utils";
  2. import ChristmasLights from "@/components/ChristmasLights.vue";
  3. import { useTestUtils } from "@/composables/useTestUtils";
  4. import { useUserAuthStore } from "@/stores/userAuth";
  5. const { getWrapper } = useTestUtils();
  6. describe("ChristmasLights component", () => {
  7. beforeEach(async context => {
  8. context.wrapper = await getWrapper(ChristmasLights);
  9. });
  10. test("small prop", async ({ wrapper }) => {
  11. await wrapper.setProps({
  12. small: false
  13. });
  14. expect(wrapper.classes()).not.toContain("christmas-lights-small");
  15. await wrapper.setProps({
  16. small: true
  17. });
  18. expect(wrapper.classes()).toContain("christmas-lights-small");
  19. });
  20. test("lights prop", async ({ wrapper }) => {
  21. await wrapper.setProps({
  22. lights: 10
  23. });
  24. expect(
  25. wrapper.findAll(".christmas-lights .christmas-wire").length
  26. ).toBe(10 + 1);
  27. expect(
  28. wrapper.findAll(".christmas-lights .christmas-light").length
  29. ).toBe(10);
  30. });
  31. test("loggedIn state", async ({ wrapper }) => {
  32. const userAuthStore = useUserAuthStore();
  33. expect(userAuthStore.loggedIn).toEqual(false);
  34. expect(wrapper.classes()).not.toContain("loggedIn");
  35. userAuthStore.loggedIn = true;
  36. await flushPromises();
  37. expect(userAuthStore.loggedIn).toEqual(true);
  38. expect(wrapper.classes()).toContain("loggedIn");
  39. });
  40. });