|
1 | 1 | 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'; |
4 | 5 | import io from '../__mocks__/socket.io-client'; |
5 | 6 |
|
6 | 7 | it('should be vue plugin (is an object with `install` method)', () => { |
@@ -96,6 +97,28 @@ describe('.install()', () => { |
96 | 97 | componentListener, |
97 | 98 | }); |
98 | 99 | }); |
| 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 | + }); |
99 | 122 | }); |
100 | 123 |
|
101 | 124 | describe('.defaults', () => { |
|
0 commit comments