Skip to content
This repository was archived by the owner on Jun 18, 2025. It is now read-only.

Commit 3d71cc3

Browse files
committed
Add unit tests fo $socket injection
1 parent 126e8f3 commit 3d71cc3

File tree

1 file changed

+25
-2
lines changed

1 file changed

+25
-2
lines changed

src/__tests__/plugin.spec.js

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { mount } from '@vue/test-utils';
2-
import { createApp } from 'vue';
3-
import Main from '../plugin';
2+
import { createApp, inject } from 'vue';
3+
import { SocketExtensionKey } from '..';
4+
import Main, { useSocket } from '../plugin';
45
import io from '../__mocks__/socket.io-client';
56

67
it('should be vue plugin (is an object with `install` method)', () => {
@@ -96,6 +97,28 @@ describe('.install()', () => {
9697
componentListener,
9798
});
9899
});
100+
101+
it('provides $socket to be injectable via the SocketExtensionKey symbol within setup()', () => {
102+
let injectedSocketExtension;
103+
const wrapper = mount({
104+
render: () => null,
105+
setup() {
106+
injectedSocketExtension = inject(SocketExtensionKey);
107+
},
108+
}, { global: { plugins: [[Main, io('ws://localhost')]] } });
109+
expect(injectedSocketExtension).toBe(wrapper.vm.$socket);
110+
});
111+
112+
it('provides a useSocket() helper function to inject $socket', () => {
113+
let injectedSocketExtension;
114+
const wrapper = mount({
115+
render: () => null,
116+
setup() {
117+
injectedSocketExtension = useSocket();
118+
},
119+
}, { global: { plugins: [[Main, io('ws://localhost')]] } });
120+
expect(injectedSocketExtension).toBe(wrapper.vm.$socket);
121+
});
99122
});
100123

101124
describe('.defaults', () => {

0 commit comments

Comments
 (0)