Skip to content

Commit

Permalink
added some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
synan798 committed Dec 22, 2024
1 parent 6b6de29 commit 431ec01
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 2 deletions.
43 changes: 43 additions & 0 deletions components/__tests__/home/Users/UserBox.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { describe, it, expect } from 'vitest';
import { mountSuspended } from '@nuxt/test-utils/runtime';
import UserBox from '~/components/home/Users/UserBox.vue'; // Replace with the actual path to your component

describe('UserBox', () => {
const props = {
profilePicture: "https://example.com/profile.jpg",
name: "Test User",
userTurn: true,
friendRequest: false,
friendshipId: 1,
friendsStatus: "PENDING",
friendId: "123",
viewType: 0,
startGame: false,
};

it('renders the user name correctly', async () => {
const wrapper = await mountSuspended(UserBox, { props });
expect(wrapper.text()).toContain(props.name);
});

it('displays the profile picture with the correct src', async () => {
const wrapper = await mountSuspended(UserBox, { props });
const img = wrapper.find('img');
expect(img.attributes('src')).toBe(props.profilePicture);
});

it('emits chose_friend when userTurn and startGame are true', async () => {
const wrapper = await mountSuspended(UserBox, {
props: { ...props, userTurn: true, startGame: true },
});
await wrapper.trigger('click');
expect(wrapper.emitted('chose_friend')).toBeTruthy();

Check failure on line 34 in components/__tests__/home/Users/UserBox.test.ts

View workflow job for this annotation

GitHub Actions / eslint

components/__tests__/home/Users/UserBox.test.ts > UserBox > emits chose_friend when userTurn and startGame are true

AssertionError: expected undefined to be truthy - Expected: true + Received: undefined ❯ components/__tests__/home/Users/UserBox.test.ts:34:45
expect(wrapper.emitted('chose_friend')[0]).toEqual([props.friendId]);
});

it('shows the modal when clicked and startGame is false', async () => {
const wrapper = await mountSuspended(UserBox, { props });
await wrapper.trigger('click');
expect(wrapper.findComponent({ name: 'ProfileUserModal' }).isVisible()).toBe(true);
});
});
2 changes: 0 additions & 2 deletions components/__tests__/login/ProviderButton.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,4 @@ describe('ProviderButton', () => {
const wrapper = await mountSuspended(ProviderButton,{props: {provider: provider.id, name: provider.name}});
expect(wrapper.text()).toContain('Sign in with ' + provider.name);
});


});

0 comments on commit 431ec01

Please sign in to comment.