+156
-148
lines changedFilter options
+156
-148
lines changed Original file line number Diff line number Diff line change
@@ -36,17 +36,26 @@
36
36
</section>
37
37
</template>
38
38
<script>
39
+
import { onMounted, ref } from 'vue';
40
+
39
41
export default {
40
-
data() {
42
+
setup() {
43
+
const show = ref(false);
44
+
const dropdown = ref(null);
45
+
const ele = ref([]);
46
+
const selected = ref([]);
47
+
48
+
onMounted(() => {
49
+
ele.value.push(dropdown.value.$el);
50
+
});
51
+
41
52
return {
42
-
show: false,
43
-
ele: [],
44
-
selected: [],
53
+
ele,
54
+
dropdown,
55
+
show,
56
+
selected,
45
57
};
46
58
},
47
-
mounted() {
48
-
this.ele.push(this.$refs.dropdown.$el);
49
-
},
50
59
};
51
60
</script>
52
61
<style>
Original file line number Diff line number Diff line change
@@ -100,3 +100,12 @@ export const triggerKey = (el, key, type = 'down') => {
100
100
el.dispatchEvent(eventObj);
101
101
}
102
102
};
103
+
104
+
export function windowClick(target) {
105
+
let e = new Event('click');
106
+
Object.defineProperty(e, 'target', {
107
+
writable: false,
108
+
value: target,
109
+
});
110
+
window.dispatchEvent(e);
111
+
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
1
-
import { createWrapper, nextTick, triggerEvent } from '../../__test__/utils';
1
+
import {
2
+
createWrapper,
3
+
nextTick,
4
+
triggerEvent,
5
+
windowClick,
6
+
} from '../../__test__/utils';
2
7
import Dropdown from './Dropdown';
3
8
4
9
function appendToBodyVm() {
@@ -176,8 +181,7 @@ describe('Dropdown', () => {
176
181
expect(dropdown.classes()).not.toContain('open');
177
182
await triggerEvent(trigger, 'click');
178
183
expect(dropdown.classes()).toContain('open');
179
-
// Simulate a window click
180
-
wrapper.vm.$refs.dropdown.windowClicked({ target: document.body });
184
+
windowClick(document.body);
181
185
await nextTick();
182
186
expect(dropdown.classes()).not.toContain('open');
183
187
});
@@ -207,18 +211,15 @@ describe('Dropdown', () => {
207
211
const dropdown = wrapper;
208
212
expect(dropdown.element.tagName.toLowerCase()).toEqual('div');
209
213
expect(dropdown.classes()).toContain('open');
210
-
// Simulate a window click
211
-
wrapper.vm.$refs.test.windowClicked({ target: wrapper.vm.$refs.li1 });
214
+
windowClick(wrapper.vm.$refs.li1);
212
215
await nextTick();
213
216
expect(dropdown.classes()).toContain('open');
214
-
// Simulate a window click
215
-
wrapper.vm.$refs.test.windowClicked({ target: document.body });
217
+
windowClick(document.body);
216
218
await nextTick();
217
219
expect(dropdown.classes()).not.toContain('open');
218
220
wrapper.vm.show = true;
219
221
await nextTick();
220
-
// Simulate a window click
221
-
wrapper.vm.$refs.test.windowClicked({ target: wrapper.vm.$refs.li2 });
222
+
windowClick(wrapper.vm.$refs.li2);
222
223
await nextTick();
223
224
expect(dropdown.classes()).not.toContain('open');
224
225
});
You can’t perform that action at this time.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4