@{{ login }}
@@ -11,17 +11,17 @@
diff --git a/docs/.vuepress/config.js b/docs/.vuepress/config.js
index ecfdb3e..ee16a29 100644
--- a/docs/.vuepress/config.js
+++ b/docs/.vuepress/config.js
@@ -1,7 +1,7 @@
-const {description} = require('./config/meta');
-const head = require('./config/head');
-const plugins = require('./config/plugins');
-const themeConfig = require('./config/themeConfig');
+const { description } = require('./config/meta')
+const head = require('./config/head')
+const plugins = require('./config/plugins')
+const themeConfig = require('./config/themeConfig')
module.exports = {
title: 'Vue Select',
@@ -9,5 +9,4 @@ module.exports = {
head,
plugins,
themeConfig,
-};
-
+}
diff --git a/docs/.vuepress/config/head.js b/docs/.vuepress/config/head.js
index 372c8cc..946d6ab 100644
--- a/docs/.vuepress/config/head.js
+++ b/docs/.vuepress/config/head.js
@@ -1,57 +1,67 @@
-const isDeployPreview = require('./isDeployPreview');
-const meta = require('./meta');
+const isDeployPreview = require('./isDeployPreview')
+const meta = require('./meta')
const head = [
[
'link',
{
- href: '//fonts.googleapis.com/css?family=Source+Sans+Pro:400,600|Roboto Mono',
+ href:
+ '//fonts.googleapis.com/css?family=Source+Sans+Pro:400,600|Roboto Mono',
rel: 'stylesheet',
type: 'text/css',
- }],
+ },
+ ],
[
'link',
{
href: '//fonts.googleapis.com/css?family=Dosis:300&text=Vue Select',
rel: 'stylesheet',
type: 'text/css',
- }],
- ['link', {rel: 'icon', href: `/vue-logo.png`}],
- ['meta', {name: 'theme-color', content: '#3eaf7c'}],
- ['meta', {name: 'apple-mobile-web-app-capable', content: 'yes'}],
- ['meta', {name: 'apple-mobile-web-app-status-bar-style', content: 'black'}],
+ },
+ ],
+ ['link', { rel: 'icon', href: `/vue-logo.png` }],
+ ['meta', { name: 'theme-color', content: '#3eaf7c' }],
+ ['meta', { name: 'apple-mobile-web-app-capable', content: 'yes' }],
+ ['meta', { name: 'apple-mobile-web-app-status-bar-style', content: 'black' }],
[
'link',
- {rel: 'apple-touch-icon', href: `/icons/apple-touch-icon-152x152.png`}],
+ { rel: 'apple-touch-icon', href: `/icons/apple-touch-icon-152x152.png` },
+ ],
[
'link',
- {rel: 'mask-icon', href: '/icons/safari-pinned-tab.svg', color: '#3eaf7c'}],
+ {
+ rel: 'mask-icon',
+ href: '/icons/safari-pinned-tab.svg',
+ color: '#3eaf7c',
+ },
+ ],
[
'meta',
{
name: 'msapplication-TileImage',
content: '/icons/msapplication-icon-144x144.png',
- }],
- ['meta', {name: 'msapplication-TileColor', content: '#000000'}],
- ['meta', {name: 'title', content: meta.title}],
- ['meta', {name: 'description', content: meta.description}],
- ['link', {rel: 'icon', href: meta.icon, type: 'image/png'}],
- ['meta', {property: 'og:image', content: meta.icon}],
- ['meta', {property: 'twitter:image', content: meta.icon}],
- ['meta', {name: 'description', content: meta.description}],
- ['meta', {property: 'og:description', content: ''}],
- ['meta', {property: 'twitter:description', content: meta.description}],
- ['meta', {property: 'twitter:title', content: meta.title}],
- ['meta', {property: 'og:title', content: meta.title}],
- ['meta', {property: 'og:site_name', content: meta.title}],
- ['meta', {property: 'og:url', content: meta.url}],
-];
+ },
+ ],
+ ['meta', { name: 'msapplication-TileColor', content: '#000000' }],
+ ['meta', { name: 'title', content: meta.title }],
+ ['meta', { name: 'description', content: meta.description }],
+ ['link', { rel: 'icon', href: meta.icon, type: 'image/png' }],
+ ['meta', { property: 'og:image', content: meta.icon }],
+ ['meta', { property: 'twitter:image', content: meta.icon }],
+ ['meta', { name: 'description', content: meta.description }],
+ ['meta', { property: 'og:description', content: '' }],
+ ['meta', { property: 'twitter:description', content: meta.description }],
+ ['meta', { property: 'twitter:title', content: meta.title }],
+ ['meta', { property: 'og:title', content: meta.title }],
+ ['meta', { property: 'og:site_name', content: meta.title }],
+ ['meta', { property: 'og:url', content: meta.url }],
+]
if (isDeployPreview) {
head.push(
- ['meta', {name: 'robots', content: 'noindex'}],
- ['meta', {name: 'googlebot', content: 'noindex'}],
- );
+ ['meta', { name: 'robots', content: 'noindex' }],
+ ['meta', { name: 'googlebot', content: 'noindex' }]
+ )
}
-module.exports = head;
+module.exports = head
diff --git a/docs/.vuepress/config/isDeployPreview.js b/docs/.vuepress/config/isDeployPreview.js
index 47bb083..ee53cc0 100644
--- a/docs/.vuepress/config/isDeployPreview.js
+++ b/docs/.vuepress/config/isDeployPreview.js
@@ -1 +1 @@
-module.exports = process.env.hasOwnProperty('DEPLOY_PREVIEW');
+module.exports = process.env.hasOwnProperty('DEPLOY_PREVIEW')
diff --git a/docs/.vuepress/config/meta.js b/docs/.vuepress/config/meta.js
index 8a7bb23..42adfb0 100644
--- a/docs/.vuepress/config/meta.js
+++ b/docs/.vuepress/config/meta.js
@@ -1,6 +1,7 @@
module.exports = {
title: 'Vue Select | VueJS Select2/Chosen Component',
- description: 'Everything you wish the HTML select element could do, wrapped up into a lightweight, extensible Vue component.',
+ description:
+ 'Everything you wish the HTML select element could do, wrapped up into a lightweight, extensible Vue component.',
url: 'https://vue-select.org',
- icon: '/vue-logo.png'
-};
+ icon: '/vue-logo.png',
+}
diff --git a/docs/.vuepress/config/plugins.js b/docs/.vuepress/config/plugins.js
index a1e61cd..aa3d259 100644
--- a/docs/.vuepress/config/plugins.js
+++ b/docs/.vuepress/config/plugins.js
@@ -1,22 +1,22 @@
-const isDeployPreview = require("./isDeployPreview");
+const isDeployPreview = require('./isDeployPreview')
module.exports = [
[
- "@vuepress/google-analytics",
+ '@vuepress/google-analytics',
{
- ga: isDeployPreview ? "" : "UA-12818324-8"
- }
+ ga: isDeployPreview ? '' : 'UA-12818324-8',
+ },
],
[
- "@vuepress/pwa",
+ '@vuepress/pwa',
{
serviceWorker: false,
- updatePopup: true
- }
+ updatePopup: true,
+ },
],
- "@vuepress/plugin-register-components",
- "@vuepress/plugin-active-header-links",
- "@vuepress/plugin-search",
- "@vuepress/plugin-nprogress",
- require('../github/index')
-];
+ '@vuepress/plugin-register-components',
+ '@vuepress/plugin-active-header-links',
+ '@vuepress/plugin-search',
+ '@vuepress/plugin-nprogress',
+ require('../github/index'),
+]
diff --git a/docs/.vuepress/config/themeConfig.js b/docs/.vuepress/config/themeConfig.js
index 921ed38..456abcf 100644
--- a/docs/.vuepress/config/themeConfig.js
+++ b/docs/.vuepress/config/themeConfig.js
@@ -2,9 +2,7 @@ module.exports = {
repo: 'sagalbot/vue-select',
editLinks: true,
docsDir: 'docs',
- nav: [
- {text: 'Sandbox', link: '/sandbox'},
- ],
+ nav: [{ text: 'Sandbox', link: '/sandbox' }],
sidebar: {
'/': [
{
@@ -75,4 +73,4 @@ module.exports = {
},
],
},
-};
+}
diff --git a/docs/.vuepress/enhanceApp.js b/docs/.vuepress/enhanceApp.js
index a3fac4d..62f5b3b 100644
--- a/docs/.vuepress/enhanceApp.js
+++ b/docs/.vuepress/enhanceApp.js
@@ -1,20 +1,19 @@
-import vSelect from '../../src/components/Select';
+import vSelect from '../../src/components/Select'
-export default ({Vue, options, router, siteData}) => {
- Vue.component('v-select', vSelect);
+export default ({ Vue, options, router, siteData }) => {
+ Vue.component('v-select', vSelect)
/**
* Remove service workers.
*/
if (typeof navigator !== 'undefined' && 'serviceWorker' in navigator) {
- navigator.serviceWorker.getRegistrations().then(registrations => {
- registrations.forEach(registration => {
+ navigator.serviceWorker.getRegistrations().then((registrations) => {
+ registrations.forEach((registration) => {
registration
.unregister()
.then(() => console.log('Service worker unregistered.'))
- .catch(() => console.log('Error unregistering service worker.'));
- });
- });
+ .catch(() => console.log('Error unregistering service worker.'))
+ })
+ })
}
-
}
diff --git a/docs/.vuepress/github/clientDynamicModules.js b/docs/.vuepress/github/clientDynamicModules.js
index e4a76f5..55fdfe6 100644
--- a/docs/.vuepress/github/clientDynamicModules.js
+++ b/docs/.vuepress/github/clientDynamicModules.js
@@ -1,14 +1,14 @@
-require("dotenv").config();
-const axios = require("axios");
-const { graphql } = require("@octokit/graphql");
+require('dotenv').config()
+const axios = require('axios')
+const { graphql } = require('@octokit/graphql')
module.exports = async () => ({
- name: "constants.js",
+ name: 'constants.js',
content: `
export const SPONSORS = ${JSON.stringify(await getSponsors())};
export const CONTRIBUTORS = ${JSON.stringify(await getContributors())};
- `
-});
+ `,
+})
/**
* Get a list of vue select contributors.
@@ -16,10 +16,10 @@ module.exports = async () => ({
*/
async function getContributors() {
const { data } = await axios.get(
- "https://api.github.com/repos/sagalbot/vue-select/contributors?per_page=100"
- );
+ 'https://api.github.com/repos/sagalbot/vue-select/contributors?per_page=100'
+ )
- return data;
+ return data
}
/**
@@ -49,17 +49,17 @@ async function getSponsors() {
}
}
}
- `;
+ `
try {
const { user } = await graphql(query, {
headers: {
- authorization: `token ${process.env.GITHUB_TOKEN || ""}`
- }
- });
- return user.sponsorshipsAsMaintainer.nodes;
+ authorization: `token ${process.env.GITHUB_TOKEN || ''}`,
+ },
+ })
+ return user.sponsorshipsAsMaintainer.nodes
} catch (e) {
- console.log(`${e.status} ${e.name} - Couldn't fetch sponsor data.`);
- return [];
+ console.log(`${e.status} ${e.name} - Couldn't fetch sponsor data.`)
+ return []
}
}
diff --git a/docs/.vuepress/github/index.js b/docs/.vuepress/github/index.js
index 39059d2..6f06662 100644
--- a/docs/.vuepress/github/index.js
+++ b/docs/.vuepress/github/index.js
@@ -1,5 +1,5 @@
-const clientDynamicModules = require('./clientDynamicModules');
+const clientDynamicModules = require('./clientDynamicModules')
module.exports = {
clientDynamicModules: async () => await clientDynamicModules(),
-};
+}
diff --git a/docs/.vuepress/theme/components/EthicalAds.vue b/docs/.vuepress/theme/components/EthicalAds.vue
index b5823f3..b6e9a69 100644
--- a/docs/.vuepress/theme/components/EthicalAds.vue
+++ b/docs/.vuepress/theme/components/EthicalAds.vue
@@ -3,19 +3,6 @@
* @see https://ethical-ad-client.readthedocs.io/en/latest/
*/
export default {
- render(h) {
- return h("div", {
- attrs: {
- id: "ads",
- "data-ea-publisher": "vue-select",
- "data-ea-type": "image"
- },
- class: "flat horizontal"
- });
- },
- mounted() {
- this.load();
- },
watch: {
$route(to, from) {
if (
@@ -23,24 +10,37 @@ export default {
// Only reload if the ad has been loaded
// otherwise it's possible that the script is appended but
// the ads are not loaded yet. This would result in duplicated ads.
- [...this.$el.classList].includes("loaded")
+ [...this.$el.classList].includes('loaded')
) {
- this.$el.innerHTML = "";
- this.$el.classList.remove("loaded");
- this.load();
+ this.$el.innerHTML = ''
+ this.$el.classList.remove('loaded')
+ this.load()
}
- }
+ },
+ },
+ mounted() {
+ this.load()
},
methods: {
load() {
- const s = document.createElement("script");
- s.id = "_ads_js";
- s.src = `https://media.ethicalads.io/media/client/ethicalads.min.js`;
- s.async = "async";
- this.$el.appendChild(s);
- }
- }
-};
+ const s = document.createElement('script')
+ s.id = '_ads_js'
+ s.src = `https://media.ethicalads.io/media/client/ethicalads.min.js`
+ s.async = 'async'
+ this.$el.appendChild(s)
+ },
+ },
+ render(h) {
+ return h('div', {
+ attrs: {
+ id: 'ads',
+ 'data-ea-publisher': 'vue-select',
+ 'data-ea-type': 'image',
+ },
+ class: 'flat horizontal',
+ })
+ },
+}
\ No newline at end of file
+
diff --git a/docs/.vuepress/theme/index.js b/docs/.vuepress/theme/index.js
index 85eb83a..4e8138f 100644
--- a/docs/.vuepress/theme/index.js
+++ b/docs/.vuepress/theme/index.js
@@ -1,3 +1,3 @@
module.exports = {
extend: '@vuepress/theme-default',
-};
+}
diff --git a/docs/.vuepress/theme/layouts/Layout.vue b/docs/.vuepress/theme/layouts/Layout.vue
index c60a619..3203dbe 100644
--- a/docs/.vuepress/theme/layouts/Layout.vue
+++ b/docs/.vuepress/theme/layouts/Layout.vue
@@ -3,13 +3,13 @@
-
-
-
-
+
+
+
-
+
{{ getOptionLabel(option) }}
-
-
+
-
+
-
+
- Loading...
+ Loading...
-
-
diff --git a/src/components/childComponents.js b/src/components/childComponents.js
index ab01201..82c97f8 100644
--- a/src/components/childComponents.js
+++ b/src/components/childComponents.js
@@ -1,7 +1,7 @@
-import Deselect from './Deselect';
-import OpenIndicator from './OpenIndicator';
+import Deselect from './Deselect'
+import OpenIndicator from './OpenIndicator'
export default {
Deselect,
- OpenIndicator
+ OpenIndicator,
}
diff --git a/src/directives/appendToBody.js b/src/directives/appendToBody.js
index 3c44567..c83d26f 100644
--- a/src/directives/appendToBody.js
+++ b/src/directives/appendToBody.js
@@ -1,27 +1,34 @@
export default {
- inserted (el, bindings, {context}) {
- if (context.appendToBody) {
- const {height, top, left, width} = context.$refs.toggle.getBoundingClientRect();
- let scrollX = window.scrollX || window.pageXOffset;
- let scrollY = window.scrollY || window.pageYOffset;
- el.unbindPosition = context.calculatePosition(el, context, {
- width: width + 'px',
- left: (scrollX + left) + 'px',
- top: (scrollY + top + height) + 'px',
- });
-
- document.body.appendChild(el);
- }
- },
+ inserted(el, bindings, { context }) {
+ if (context.appendToBody) {
+ const {
+ height,
+ top,
+ left,
+ width,
+ } = context.$refs.toggle.getBoundingClientRect()
- unbind (el, bindings, {context}) {
- if (context.appendToBody) {
- if (el.unbindPosition && typeof el.unbindPosition === 'function') {
- el.unbindPosition();
- }
- if (el.parentNode) {
- el.parentNode.removeChild(el);
- }
- }
- },
+ let scrollX = window.scrollX || window.pageXOffset
+ let scrollY = window.scrollY || window.pageYOffset
+
+ el.unbindPosition = context.calculatePosition(el, context, {
+ width: width + 'px',
+ left: scrollX + left + 'px',
+ top: scrollY + top + height + 'px',
+ })
+
+ document.body.appendChild(el)
+ }
+ },
+
+ unbind(el, bindings, { context }) {
+ if (context.appendToBody) {
+ if (el.unbindPosition && typeof el.unbindPosition === 'function') {
+ el.unbindPosition()
+ }
+ if (el.parentNode) {
+ el.parentNode.removeChild(el)
+ }
+ }
+ },
}
diff --git a/src/mixins/ajax.js b/src/mixins/ajax.js
index 80d1950..ce8b9ad 100644
--- a/src/mixins/ajax.js
+++ b/src/mixins/ajax.js
@@ -11,10 +11,10 @@ export default {
},
},
- data () {
+ data() {
return {
mutableLoading: false,
- };
+ }
},
watch: {
@@ -27,8 +27,8 @@ export default {
*
* @emits search
*/
- search () {
- this.$emit('search', this.search, this.toggleLoading);
+ search() {
+ this.$emit('search', this.search, this.toggleLoading)
},
/**
@@ -36,8 +36,8 @@ export default {
* mutable loading value.
* @param val
*/
- loading (val) {
- this.mutableLoading = val;
+ loading(val) {
+ this.mutableLoading = val
},
},
@@ -49,11 +49,11 @@ export default {
* @param toggle Boolean
* @returns {*}
*/
- toggleLoading (toggle = null) {
+ toggleLoading(toggle = null) {
if (toggle == null) {
- return (this.mutableLoading = !this.mutableLoading);
+ return (this.mutableLoading = !this.mutableLoading)
}
- return (this.mutableLoading = toggle);
+ return (this.mutableLoading = toggle)
},
},
-};
+}
diff --git a/src/mixins/pointerScroll.js b/src/mixins/pointerScroll.js
index 23d80ee..058df04 100644
--- a/src/mixins/pointerScroll.js
+++ b/src/mixins/pointerScroll.js
@@ -2,14 +2,14 @@ export default {
props: {
autoscroll: {
type: Boolean,
- default: true
- }
+ default: true,
+ },
},
watch: {
typeAheadPointer() {
if (this.autoscroll) {
- this.maybeAdjustScroll();
+ this.maybeAdjustScroll()
}
},
},
@@ -23,17 +23,17 @@ export default {
*/
maybeAdjustScroll() {
const optionEl =
- this.$refs.dropdownMenu?.children[this.typeAheadPointer] || false;
+ this.$refs.dropdownMenu?.children[this.typeAheadPointer] || false
if (optionEl) {
- const bounds = this.getDropdownViewport();
- const { top, bottom, height } = optionEl.getBoundingClientRect();
+ const bounds = this.getDropdownViewport()
+ const { top, bottom, height } = optionEl.getBoundingClientRect()
if (top < bounds.top) {
- return (this.$refs.dropdownMenu.scrollTop = optionEl.offsetTop);
+ return (this.$refs.dropdownMenu.scrollTop = optionEl.offsetTop)
} else if (bottom > bounds.bottom) {
return (this.$refs.dropdownMenu.scrollTop =
- optionEl.offsetTop - (bounds.height - height));
+ optionEl.offsetTop - (bounds.height - height))
}
}
},
@@ -48,8 +48,8 @@ export default {
: {
height: 0,
top: 0,
- bottom: 0
- };
- }
- }
-};
+ bottom: 0,
+ }
+ },
+ },
+}
diff --git a/src/mixins/typeAheadPointer.js b/src/mixins/typeAheadPointer.js
index b878676..849cfda 100644
--- a/src/mixins/typeAheadPointer.js
+++ b/src/mixins/typeAheadPointer.js
@@ -1,7 +1,7 @@
export default {
data() {
return {
- typeAheadPointer: -1
+ typeAheadPointer: -1,
}
},
@@ -9,11 +9,11 @@ export default {
filteredOptions() {
for (let i = 0; i < this.filteredOptions.length; i++) {
if (this.selectable(this.filteredOptions[i])) {
- this.typeAheadPointer = i;
- break;
+ this.typeAheadPointer = i
+ break
}
}
- }
+ },
},
methods: {
@@ -25,8 +25,8 @@ export default {
typeAheadUp() {
for (let i = this.typeAheadPointer - 1; i >= 0; i--) {
if (this.selectable(this.filteredOptions[i])) {
- this.typeAheadPointer = i;
- break;
+ this.typeAheadPointer = i
+ break
}
}
},
@@ -37,10 +37,14 @@ export default {
* @return {void}
*/
typeAheadDown() {
- for (let i = this.typeAheadPointer + 1; i < this.filteredOptions.length; i++) {
+ for (
+ let i = this.typeAheadPointer + 1;
+ i < this.filteredOptions.length;
+ i++
+ ) {
if (this.selectable(this.filteredOptions[i])) {
- this.typeAheadPointer = i;
- break;
+ this.typeAheadPointer = i
+ break
}
}
},
@@ -51,11 +55,11 @@ export default {
* @return {void}
*/
typeAheadSelect() {
- const typeAheadOption = this.filteredOptions[this.typeAheadPointer];
+ const typeAheadOption = this.filteredOptions[this.typeAheadPointer]
if (typeAheadOption) {
- this.select(typeAheadOption);
+ this.select(typeAheadOption)
}
- }
- }
+ },
+ },
}
diff --git a/src/utility/sortAndStringify.js b/src/utility/sortAndStringify.js
index 14a619d..1881fb1 100644
--- a/src/utility/sortAndStringify.js
+++ b/src/utility/sortAndStringify.js
@@ -3,13 +3,15 @@
* @return {string}
*/
function sortAndStringify(sortable) {
- const ordered = {};
+ const ordered = {}
- Object.keys(sortable).sort().forEach(key => {
- ordered[key] = sortable[key];
- });
+ Object.keys(sortable)
+ .sort()
+ .forEach((key) => {
+ ordered[key] = sortable[key]
+ })
- return JSON.stringify(ordered);
+ return JSON.stringify(ordered)
}
-export default sortAndStringify;
+export default sortAndStringify
diff --git a/src/utility/uniqueId.js b/src/utility/uniqueId.js
index 8e96640..53de592 100644
--- a/src/utility/uniqueId.js
+++ b/src/utility/uniqueId.js
@@ -1,4 +1,4 @@
-let idCount = 0;
+let idCount = 0
/**
* Dead simple unique ID implementation.
@@ -6,7 +6,7 @@ let idCount = 0;
* @return {number}
*/
function uniqueId() {
- return ++idCount;
+ return ++idCount
}
-export default uniqueId;
+export default uniqueId
diff --git a/tests/helpers.js b/tests/helpers.js
index e055155..3b8c195 100755
--- a/tests/helpers.js
+++ b/tests/helpers.js
@@ -1,6 +1,6 @@
-import { shallowMount } from "@vue/test-utils";
-import VueSelect from "../src/components/Select.vue";
-import Vue from 'vue';
+import { shallowMount } from '@vue/test-utils'
+import VueSelect from '../src/components/Select.vue'
+import Vue from 'vue'
/**
* Trigger a submit event on the search
@@ -11,10 +11,10 @@ import Vue from 'vue';
*/
export const searchSubmit = (Wrapper, searchText = false) => {
if (searchText) {
- Wrapper.vm.search = searchText;
+ Wrapper.vm.search = searchText
}
- Wrapper.find({ ref: "search" }).trigger("keydown.enter")
-};
+ Wrapper.find({ ref: 'search' }).trigger('keydown.enter')
+}
/**
* Focus the input, enter some search text, hit return.
@@ -23,15 +23,15 @@ export const searchSubmit = (Wrapper, searchText = false) => {
* @return {Promise}
*/
export const selectTag = async (Wrapper, searchText) => {
- Wrapper.vm.$refs.search.focus();
- await Wrapper.vm.$nextTick();
+ Wrapper.vm.$refs.search.focus()
+ await Wrapper.vm.$nextTick()
- Wrapper.vm.search = searchText;
- await Wrapper.vm.$nextTick();
+ Wrapper.vm.search = searchText
+ await Wrapper.vm.$nextTick()
- Wrapper.find({ ref: "search" }).trigger("keydown.enter");
- await Wrapper.vm.$nextTick();
-};
+ Wrapper.find({ ref: 'search' }).trigger('keydown.enter')
+ await Wrapper.vm.$nextTick()
+}
/**
* Create a new VueSelect instance with
@@ -40,8 +40,8 @@ export const selectTag = async (Wrapper, searchText) => {
* @returns {Wrapper}
*/
export const selectWithProps = (propsData = {}) => {
- return shallowMount(VueSelect, { propsData });
-};
+ return shallowMount(VueSelect, { propsData })
+}
/**
* Returns a Wrapper with a v-select component.
@@ -56,9 +56,8 @@ export const mountDefault = (props = {}, options = {}) => {
...props,
},
...options,
- });
-};
-
+ })
+}
/**
* Returns a v-select component directly.
@@ -68,11 +67,12 @@ export const mountDefault = (props = {}, options = {}) => {
*/
export const mountWithoutTestUtils = (props = {}, options = {}) => {
return new Vue({
- render: createEl => createEl('vue-select', {
- ref: 'select',
- props: {options: ['one', 'two', 'three'], ...props},
- ...options
- }),
- components: {VueSelect},
- }).$mount().$refs.select;
-};
+ components: { VueSelect },
+ render: (createEl) =>
+ createEl('vue-select', {
+ ref: 'select',
+ props: { options: ['one', 'two', 'three'], ...props },
+ ...options,
+ }),
+ }).$mount().$refs.select
+}
diff --git a/tests/unit/.eslintrc.js b/tests/unit/.eslintrc.js
index 4e51c63..cb33828 100755
--- a/tests/unit/.eslintrc.js
+++ b/tests/unit/.eslintrc.js
@@ -1,8 +1,8 @@
module.exports = {
env: {
- jest: true
+ jest: true,
},
rules: {
- 'import/no-extraneous-dependencies': 'off'
- }
-}
\ No newline at end of file
+ 'import/no-extraneous-dependencies': 'off',
+ },
+}
diff --git a/tests/unit/Accessibility.spec.js b/tests/unit/Accessibility.spec.js
index 793b76e..2180f42 100644
--- a/tests/unit/Accessibility.spec.js
+++ b/tests/unit/Accessibility.spec.js
@@ -1,35 +1,35 @@
-import { mountDefault } from "../helpers";
+import { mountDefault } from '../helpers'
-describe("Search Slot Scope", () => {
+describe('Search Slot Scope', () => {
/**
* @see https://www.w3.org/WAI/PF/aria/states_and_properties#aria-activedescendant
*/
- describe("aria-activedescendant", () => {
- it("adds the active descendant attribute only when the dropdown is open and there is a typeAheadPointer value", async () => {
- const Select = mountDefault();
+ describe('aria-activedescendant', () => {
+ it('adds the active descendant attribute only when the dropdown is open and there is a typeAheadPointer value', async () => {
+ const Select = mountDefault()
expect(
- Select.vm.scope.search.attributes["aria-activedescendant"]
- ).toEqual(undefined);
+ Select.vm.scope.search.attributes['aria-activedescendant']
+ ).toEqual(undefined)
- Select.vm.open = true;
- await Select.vm.$nextTick();
+ Select.vm.open = true
+ await Select.vm.$nextTick()
expect(
- Select.vm.scope.search.attributes["aria-activedescendant"]
- ).toEqual(undefined);
- });
+ Select.vm.scope.search.attributes['aria-activedescendant']
+ ).toEqual(undefined)
+ })
it("adds the active descendant attribute when there's a typeahead value and an open dropdown", async () => {
- const Select = mountDefault();
+ const Select = mountDefault()
- Select.vm.open = true;
- Select.vm.typeAheadPointer = 1;
- await Select.vm.$nextTick();
+ Select.vm.open = true
+ Select.vm.typeAheadPointer = 1
+ await Select.vm.$nextTick()
expect(
- Select.vm.scope.search.attributes["aria-activedescendant"]
- ).toEqual(`vs${Select.vm.uid}__option-1`);
- });
- });
-});
+ Select.vm.scope.search.attributes['aria-activedescendant']
+ ).toEqual(`vs${Select.vm.uid}__option-1`)
+ })
+ })
+})
diff --git a/tests/unit/Ajax.spec.js b/tests/unit/Ajax.spec.js
index cfa9b79..1bacf0c 100755
--- a/tests/unit/Ajax.spec.js
+++ b/tests/unit/Ajax.spec.js
@@ -1,65 +1,65 @@
-import { selectWithProps } from "../helpers";
-import { shallowMount } from '@vue/test-utils';
-import vSelect from '../../src/components/Select';
+import { selectWithProps } from '../helpers'
+import { shallowMount } from '@vue/test-utils'
+import vSelect from '../../src/components/Select'
-describe("Asynchronous Loading", () => {
- it("can toggle the loading class", () => {
- const Select = selectWithProps();
+describe('Asynchronous Loading', () => {
+ it('can toggle the loading class', () => {
+ const Select = selectWithProps()
- Select.vm.toggleLoading();
- expect(Select.vm.mutableLoading).toEqual(true);
+ Select.vm.toggleLoading()
+ expect(Select.vm.mutableLoading).toEqual(true)
- Select.vm.toggleLoading(true);
- expect(Select.vm.mutableLoading).toEqual(true);
- });
+ Select.vm.toggleLoading(true)
+ expect(Select.vm.mutableLoading).toEqual(true)
+ })
- it("should trigger the search event when the search text changes", async () => {
- const Select = selectWithProps();
+ it('should trigger the search event when the search text changes', async () => {
+ const Select = selectWithProps()
- Select.vm.search = "foo";
- await Select.vm.$nextTick();
+ Select.vm.search = 'foo'
+ await Select.vm.$nextTick()
- const events = Select.emitted("search");
+ const events = Select.emitted('search')
- expect(events).toContainEqual(["foo", Select.vm.toggleLoading]);
- expect(events.length).toEqual(1);
- });
+ expect(events).toContainEqual(['foo', Select.vm.toggleLoading])
+ expect(events.length).toEqual(1)
+ })
- it("should trigger the search event if the search text is empty", async () => {
- const Select = selectWithProps();
+ it('should trigger the search event if the search text is empty', async () => {
+ const Select = selectWithProps()
- Select.vm.search = "foo";
- await Select.vm.$nextTick();
- Select.vm.search = "";
- await Select.vm.$nextTick();
+ Select.vm.search = 'foo'
+ await Select.vm.$nextTick()
+ Select.vm.search = ''
+ await Select.vm.$nextTick()
- const events = Select.emitted("search");
+ const events = Select.emitted('search')
- expect(events).toContainEqual(["", Select.vm.toggleLoading]);
- expect(events.length).toEqual(2);
- });
+ expect(events).toContainEqual(['', Select.vm.toggleLoading])
+ expect(events.length).toEqual(2)
+ })
- it("can set loading to false from the @search event callback", async () => {
+ it('can set loading to false from the @search event callback', async () => {
const Select = shallowMount(vSelect, {
listeners: {
search: (search, loading) => {
loading(false)
},
},
- });
+ })
- Select.vm.mutableLoading = true;
- Select.vm.search = 'foo';
- await Select.vm.$nextTick();
+ Select.vm.mutableLoading = true
+ Select.vm.search = 'foo'
+ await Select.vm.$nextTick()
- expect(Select.vm.mutableLoading).toEqual(false);
- });
+ expect(Select.vm.mutableLoading).toEqual(false)
+ })
it('will sync mutable loading with the loading prop', async () => {
- const Select = selectWithProps({ loading: false });
- Select.setProps({ loading: true });
- await Select.vm.$nextTick();
+ const Select = selectWithProps({ loading: false })
+ Select.setProps({ loading: true })
+ await Select.vm.$nextTick()
- expect(Select.vm.mutableLoading).toEqual(true);
- });
-});
+ expect(Select.vm.mutableLoading).toEqual(true)
+ })
+})
diff --git a/tests/unit/Autoscroll.spec.js b/tests/unit/Autoscroll.spec.js
index 9f8ea26..939a37a 100644
--- a/tests/unit/Autoscroll.spec.js
+++ b/tests/unit/Autoscroll.spec.js
@@ -1,61 +1,61 @@
-import { mountDefault } from "../helpers";
+import { mountDefault } from '../helpers'
-describe("Automatic Scrolling", () => {
- it("should check if the scroll position needs to be adjusted on up arrow keyUp", async () => {
+describe('Automatic Scrolling', () => {
+ it('should check if the scroll position needs to be adjusted on up arrow keyUp', async () => {
// Given
- const Select = mountDefault();
- const spy = jest.spyOn(Select.vm, "maybeAdjustScroll");
- Select.vm.typeAheadPointer = 1;
+ const Select = mountDefault()
+ const spy = jest.spyOn(Select.vm, 'maybeAdjustScroll')
+ Select.vm.typeAheadPointer = 1
// When
- Select.find({ ref: "search" }).trigger("keydown.up");
- await Select.vm.$nextTick();
+ Select.find({ ref: 'search' }).trigger('keydown.up')
+ await Select.vm.$nextTick()
// Then
- expect(spy).toHaveBeenCalled();
- });
+ expect(spy).toHaveBeenCalled()
+ })
- it("should check if the scroll position needs to be adjusted on down arrow keyUp", async () => {
+ it('should check if the scroll position needs to be adjusted on down arrow keyUp', async () => {
// Given
- const Select = mountDefault();
- const spy = jest.spyOn(Select.vm, "maybeAdjustScroll");
- Select.vm.typeAheadPointer = 1;
+ const Select = mountDefault()
+ const spy = jest.spyOn(Select.vm, 'maybeAdjustScroll')
+ Select.vm.typeAheadPointer = 1
// When
- Select.find({ ref: "search" }).trigger("keydown.down");
- await Select.vm.$nextTick();
+ Select.find({ ref: 'search' }).trigger('keydown.down')
+ await Select.vm.$nextTick()
// Then
- expect(spy).toHaveBeenCalled();
- });
+ expect(spy).toHaveBeenCalled()
+ })
- it("should check if the scroll position needs to be adjusted when filtered options changes", async () => {
+ it('should check if the scroll position needs to be adjusted when filtered options changes', async () => {
// Given
- const Select = mountDefault();
- const spy = jest.spyOn(Select.vm, "maybeAdjustScroll");
- Select.vm.typeAheadPointer = 1;
+ const Select = mountDefault()
+ const spy = jest.spyOn(Select.vm, 'maybeAdjustScroll')
+ Select.vm.typeAheadPointer = 1
// When
- Select.vm.search = "two";
- await Select.vm.$nextTick();
+ Select.vm.search = 'two'
+ await Select.vm.$nextTick()
// Then
- expect(spy).toHaveBeenCalled();
- });
+ expect(spy).toHaveBeenCalled()
+ })
- it("should not adjust scroll position when autoscroll is false", async () => {
+ it('should not adjust scroll position when autoscroll is false', async () => {
// Given
const Select = mountDefault({
- autoscroll: false
- });
- const spy = jest.spyOn(Select.vm, "maybeAdjustScroll");
- Select.vm.typeAheadPointer = 1;
+ autoscroll: false,
+ })
+ const spy = jest.spyOn(Select.vm, 'maybeAdjustScroll')
+ Select.vm.typeAheadPointer = 1
// When
- Select.vm.search = "two";
- await Select.vm.$nextTick();
+ Select.vm.search = 'two'
+ await Select.vm.$nextTick()
// Then
- expect(spy).toHaveBeenCalledTimes(0);
- });
-});
+ expect(spy).toHaveBeenCalledTimes(0)
+ })
+})
diff --git a/tests/unit/Components.spec.js b/tests/unit/Components.spec.js
index 3c43710..1c3fcb8 100644
--- a/tests/unit/Components.spec.js
+++ b/tests/unit/Components.spec.js
@@ -1,30 +1,28 @@
-import Vue from 'vue';
-import { selectWithProps } from '../helpers';
+import Vue from 'vue'
+import { selectWithProps } from '../helpers'
describe('Components API', () => {
-
it('swap the Deselect component', () => {
const Deselect = Vue.component('Deselect', {
- render (createElement) {
- return createElement('button', 'remove');
+ render(createElement) {
+ return createElement('button', 'remove')
},
- });
+ })
- const Select = selectWithProps({components: {Deselect}});
+ const Select = selectWithProps({ components: { Deselect } })
- expect(Select.contains(Deselect)).toBeTruthy();
- });
+ expect(Select.contains(Deselect)).toBeTruthy()
+ })
it('swap the OpenIndicator component', () => {
const OpenIndicator = Vue.component('OpenIndicator', {
- render (createElement) {
- return createElement('i', '^');
+ render(createElement) {
+ return createElement('i', '^')
},
- });
+ })
- const Select = selectWithProps({components: {OpenIndicator}});
+ const Select = selectWithProps({ components: { OpenIndicator } })
- expect(Select.contains(OpenIndicator)).toBeTruthy();
- });
-
-});
+ expect(Select.contains(OpenIndicator)).toBeTruthy()
+ })
+})
diff --git a/tests/unit/CreateOption.spec.js b/tests/unit/CreateOption.spec.js
index 89ff219..258e282 100644
--- a/tests/unit/CreateOption.spec.js
+++ b/tests/unit/CreateOption.spec.js
@@ -1,30 +1,30 @@
-import { searchSubmit, selectTag, selectWithProps } from "../helpers";
+import { searchSubmit, selectTag, selectWithProps } from '../helpers'
-describe("CreateOption When Tagging Is Enabled", () => {
- it("can select the current search text as a string", async () => {
+describe('CreateOption When Tagging Is Enabled', () => {
+ it('can select the current search text as a string', async () => {
const Select = selectWithProps({
taggable: true,
multiple: true,
- options: ["one", "two"],
- createOption: option => "four"
- });
+ options: ['one', 'two'],
+ createOption: (option) => 'four',
+ })
- await selectTag(Select, "three");
- expect(Select.vm.selectedValue).toEqual(["four"]);
- });
+ await selectTag(Select, 'three')
+ expect(Select.vm.selectedValue).toEqual(['four'])
+ })
- it("can select the current search text as an object", async () => {
+ it('can select the current search text as an object', async () => {
const Select = selectWithProps({
taggable: true,
multiple: false,
value: null,
options: [],
- label: "name",
- createOption: title => ({ name: title })
- });
+ label: 'name',
+ createOption: (title) => ({ name: title }),
+ })
- await selectTag(Select, "two");
+ await selectTag(Select, 'two')
- expect(Select.emitted("input")[0]).toEqual([{ name: "two" }]);
- });
-});
+ expect(Select.emitted('input')[0]).toEqual([{ name: 'two' }])
+ })
+})
diff --git a/tests/unit/Deselecting.spec.js b/tests/unit/Deselecting.spec.js
index 011acee..16f3f41 100755
--- a/tests/unit/Deselecting.spec.js
+++ b/tests/unit/Deselecting.spec.js
@@ -1,107 +1,107 @@
-import { mountDefault, selectWithProps } from '../helpers';
+import { mountDefault, selectWithProps } from '../helpers'
-describe("Removing values", () => {
- it("can remove the given tag when its close icon is clicked", async () => {
- const Select = selectWithProps({ multiple: true });
- Select.vm.$data._value = 'one';
- await Select.vm.$nextTick();
+describe('Removing values', () => {
+ it('can remove the given tag when its close icon is clicked', async () => {
+ const Select = selectWithProps({ multiple: true })
+ Select.vm.$data._value = 'one'
+ await Select.vm.$nextTick()
- Select.find(".vs__deselect").trigger("click");
- expect(Select.emitted().input).toEqual([[[]]]);
- expect(Select.vm.selectedValue).toEqual([]);
- });
+ Select.find('.vs__deselect').trigger('click')
+ expect(Select.emitted().input).toEqual([[[]]])
+ expect(Select.vm.selectedValue).toEqual([])
+ })
- it("should not remove tag when close icon is clicked and component is disabled", () => {
+ it('should not remove tag when close icon is clicked and component is disabled', () => {
const Select = selectWithProps({
- value: ["one"],
- options: ["one", "two", "three"],
+ value: ['one'],
+ options: ['one', 'two', 'three'],
multiple: true,
- disabled: true
- });
+ disabled: true,
+ })
- Select.find(".vs__deselect").trigger("click");
- expect(Select.vm.selectedValue).toEqual(["one"]);
- });
+ Select.find('.vs__deselect').trigger('click')
+ expect(Select.vm.selectedValue).toEqual(['one'])
+ })
- it("should remove the last item in the value array on delete keypress when multiple is true", () => {
+ it('should remove the last item in the value array on delete keypress when multiple is true', () => {
const Select = selectWithProps({
multiple: true,
- options: ["one", "two", "three"]
- });
+ options: ['one', 'two', 'three'],
+ })
- Select.vm.$data._value = ["one", "two"];
+ Select.vm.$data._value = ['one', 'two']
Select.find('.vs__search').trigger('keydown.backspace')
- expect(Select.emitted().input).toEqual([[['one']]]);
- expect(Select.vm.selectedValue).toEqual(["one"]);
- });
+ expect(Select.emitted().input).toEqual([[['one']]])
+ expect(Select.vm.selectedValue).toEqual(['one'])
+ })
- it("should set value to null on delete keypress when multiple is false", () => {
+ it('should set value to null on delete keypress when multiple is false', () => {
const Select = selectWithProps({
- options: ["one", "two", "three"]
- });
+ options: ['one', 'two', 'three'],
+ })
- Select.vm.$data._value = 'one';
+ Select.vm.$data._value = 'one'
- Select.vm.maybeDeleteValue();
- expect(Select.vm.selectedValue).toEqual([]);
- });
+ Select.vm.maybeDeleteValue()
+ expect(Select.vm.selectedValue).toEqual([])
+ })
it('will not emit input event if value has not changed with backspace', () => {
- const Select = mountDefault();
- Select.vm.$data._value = 'one';
- Select.find({ ref: 'search' }).trigger('keydown.backspace');
- expect(Select.emitted().input.length).toBe(1);
+ const Select = mountDefault()
+ Select.vm.$data._value = 'one'
+ Select.find({ ref: 'search' }).trigger('keydown.backspace')
+ expect(Select.emitted().input.length).toBe(1)
- Select.find({ ref: 'search' }).trigger('keydown.backspace');
- Select.find({ ref: 'search' }).trigger('keydown.backspace');
- expect(Select.emitted().input.length).toBe(1);
- });
+ Select.find({ ref: 'search' }).trigger('keydown.backspace')
+ Select.find({ ref: 'search' }).trigger('keydown.backspace')
+ expect(Select.emitted().input.length).toBe(1)
+ })
- describe("Clear button", () => {
- it("should be displayed on single select when value is selected", () => {
+ describe('Clear button', () => {
+ it('should be displayed on single select when value is selected', () => {
const Select = selectWithProps({
- options: ["foo", "bar"],
- value: "foo"
- });
+ options: ['foo', 'bar'],
+ value: 'foo',
+ })
- expect(Select.vm.showClearButton).toEqual(true);
- });
+ expect(Select.vm.showClearButton).toEqual(true)
+ })
- it("should not be displayed on multiple select", () => {
+ it('should not be displayed on multiple select', () => {
const Select = selectWithProps({
- options: ["foo", "bar"],
- value: "foo",
- multiple: true
- });
+ options: ['foo', 'bar'],
+ value: 'foo',
+ multiple: true,
+ })
- expect(Select.vm.showClearButton).toEqual(false);
- });
+ expect(Select.vm.showClearButton).toEqual(false)
+ })
- it("should remove selected value when clicked", () => {
+ it('should remove selected value when clicked', () => {
const Select = selectWithProps({
- options: ["foo", "bar"],
- });
- Select.vm.$data._value = 'foo';
+ options: ['foo', 'bar'],
+ })
+ Select.vm.$data._value = 'foo'
- expect(Select.vm.selectedValue).toEqual(["foo"]);
- Select.find("button.vs__clear").trigger("click");
+ expect(Select.vm.selectedValue).toEqual(['foo'])
+ Select.find('button.vs__clear').trigger('click')
- expect(Select.emitted().input).toEqual([[null]]);
- expect(Select.vm.selectedValue).toEqual([]);
- });
+ expect(Select.emitted().input).toEqual([[null]])
+ expect(Select.vm.selectedValue).toEqual([])
+ })
- it("should be disabled when component is disabled", () => {
+ it('should be disabled when component is disabled', () => {
const Select = selectWithProps({
- options: ["foo", "bar"],
- value: "foo",
- disabled: true
- });
+ options: ['foo', 'bar'],
+ value: 'foo',
+ disabled: true,
+ })
- expect(Select.find("button.vs__clear").attributes().disabled).toEqual(
- "disabled"
- );
- });
- });
-});
+ expect(Select.find('button.vs__clear').attributes().disabled).toEqual(
+ 'disabled'
+ )
+ })
+ })
+})
diff --git a/tests/unit/Dropdown.spec.js b/tests/unit/Dropdown.spec.js
index 7404284..f5828dd 100755
--- a/tests/unit/Dropdown.spec.js
+++ b/tests/unit/Dropdown.spec.js
@@ -1,201 +1,201 @@
-import { selectWithProps } from "../helpers";
-import OpenIndicator from "../../src/components/OpenIndicator";
+import { selectWithProps } from '../helpers'
+import OpenIndicator from '../../src/components/OpenIndicator'
const preventDefault = jest.fn()
-function clickEvent (currentTarget) {
+function clickEvent(currentTarget) {
return { currentTarget, preventDefault }
}
-describe("Toggling Dropdown", () => {
- it("should not open the dropdown when the el is clicked but the component is disabled", () => {
- const Select = selectWithProps({ disabled: true });
- Select.vm.toggleDropdown(clickEvent(Select.vm.$refs.search));
- expect(Select.vm.open).toEqual(false);
- });
-
- it("should open the dropdown when the el is clicked", () => {
- const Select = selectWithProps({
- value: [{ label: "one" }],
- options: [{ label: "one" }]
- });
-
- Select.vm.toggleDropdown(clickEvent(Select.vm.$refs.search));
- expect(Select.vm.open).toEqual(true);
- });
-
- it("should not close the dropdown when the el is clicked and enableMouseInputSearch is set to true", () => {
- const Select = selectWithProps({
- value: [{ label: "one" }],
- options: [{ label: "one" }],
- enableMouseSearchInput: true
- });
-
- Select.vm.toggleDropdown(clickEvent(Select.vm.$refs.search));
- expect(Select.vm.open).toEqual(true);
- Select.vm.toggleDropdown(clickEvent(Select.vm.$el));
+describe('Toggling Dropdown', () => {
+ it('should not open the dropdown when the el is clicked but the component is disabled', () => {
+ const Select = selectWithProps({ disabled: true })
+ Select.vm.toggleDropdown(clickEvent(Select.vm.$refs.search))
expect(Select.vm.open).toEqual(false)
- });
+ })
- it("should open the dropdown when the selected tag is clicked", () => {
+ it('should open the dropdown when the el is clicked', () => {
const Select = selectWithProps({
- value: [{ label: "one" }],
- options: [{ label: "one" }]
- });
+ value: [{ label: 'one' }],
+ options: [{ label: 'one' }],
+ })
- const selectedTag = Select.find(".vs__selected").element;
+ Select.vm.toggleDropdown(clickEvent(Select.vm.$refs.search))
+ expect(Select.vm.open).toEqual(true)
+ })
- Select.vm.toggleDropdown(clickEvent(selectedTag));
- expect(Select.vm.open).toEqual(true);
- });
+ it('should not close the dropdown when the el is clicked and enableMouseInputSearch is set to true', () => {
+ const Select = selectWithProps({
+ value: [{ label: 'one' }],
+ options: [{ label: 'one' }],
+ enableMouseSearchInput: true,
+ })
- it("can close the dropdown when the el is clicked", () => {
- const Select = selectWithProps();
- const spy = jest.spyOn(Select.vm.$refs.search, "blur");
+ Select.vm.toggleDropdown(clickEvent(Select.vm.$refs.search))
+ expect(Select.vm.open).toEqual(true)
+ Select.vm.toggleDropdown(clickEvent(Select.vm.$el))
+ expect(Select.vm.open).toEqual(false)
+ })
- Select.vm.open = true;
- Select.vm.toggleDropdown(clickEvent(Select.vm.$el));
+ it('should open the dropdown when the selected tag is clicked', () => {
+ const Select = selectWithProps({
+ value: [{ label: 'one' }],
+ options: [{ label: 'one' }],
+ })
- expect(spy).toHaveBeenCalled();
- });
+ const selectedTag = Select.find('.vs__selected').element
- it("closes the dropdown when an option is selected, multiple is true, and closeOnSelect option is true", () => {
+ Select.vm.toggleDropdown(clickEvent(selectedTag))
+ expect(Select.vm.open).toEqual(true)
+ })
+
+ it('can close the dropdown when the el is clicked', () => {
+ const Select = selectWithProps()
+ const spy = jest.spyOn(Select.vm.$refs.search, 'blur')
+
+ Select.vm.open = true
+ Select.vm.toggleDropdown(clickEvent(Select.vm.$el))
+
+ expect(spy).toHaveBeenCalled()
+ })
+
+ it('closes the dropdown when an option is selected, multiple is true, and closeOnSelect option is true', () => {
const Select = selectWithProps({
value: [],
- options: ["one", "two", "three"],
- multiple: true
- });
-
- Select.vm.open = true;
- Select.vm.select("one");
-
- expect(Select.vm.open).toEqual(false);
- });
-
- it("does not close the dropdown when the el is clicked, multiple is true, and closeOnSelect option is false", () => {
- const Select = selectWithProps({
- value: [],
- options: ["one", "two", "three"],
+ options: ['one', 'two', 'three'],
multiple: true,
- closeOnSelect: false
- });
+ })
- Select.vm.open = true;
- Select.vm.select("one");
+ Select.vm.open = true
+ Select.vm.select('one')
- expect(Select.vm.open).toEqual(true);
- });
+ expect(Select.vm.open).toEqual(false)
+ })
- it("should close the dropdown on search blur", () => {
+ it('does not close the dropdown when the el is clicked, multiple is true, and closeOnSelect option is false', () => {
const Select = selectWithProps({
- options: [{ label: "one" }]
- });
+ value: [],
+ options: ['one', 'two', 'three'],
+ multiple: true,
+ closeOnSelect: false,
+ })
- Select.vm.open = true;
- Select.find({ ref: "search" }).trigger("blur");
+ Select.vm.open = true
+ Select.vm.select('one')
- expect(Select.vm.open).toEqual(false);
- });
+ expect(Select.vm.open).toEqual(true)
+ })
- it("will close the dropdown and emit the search:blur event from onSearchBlur", () => {
- const Select = selectWithProps();
- const spy = jest.spyOn(Select.vm, "$emit");
-
- Select.vm.open = true;
- Select.vm.onSearchBlur();
-
- expect(Select.vm.open).toEqual(false);
- expect(spy).toHaveBeenCalledWith("search:blur");
- });
-
- it("will open the dropdown and emit the search:focus event from onSearchFocus", () => {
- const Select = selectWithProps();
- const spy = jest.spyOn(Select.vm, "$emit");
-
- Select.vm.onSearchFocus();
-
- expect(Select.vm.open).toEqual(true);
- expect(spy).toHaveBeenCalledWith("search:focus");
- });
-
- it("will close the dropdown on escape, if search is empty", () => {
- const Select = selectWithProps();
- const spy = jest.spyOn(Select.vm.$refs.search, "blur");
-
- Select.vm.open = true;
- Select.vm.onEscape();
-
- expect(spy).toHaveBeenCalled();
- });
-
- it("should remove existing search text on escape keydown", () => {
+ it('should close the dropdown on search blur', () => {
const Select = selectWithProps({
- value: [{ label: "one" }],
- options: [{ label: "one" }]
- });
+ options: [{ label: 'one' }],
+ })
- Select.vm.search = "foo";
+ Select.vm.open = true
+ Select.find({ ref: 'search' }).trigger('blur')
+
+ expect(Select.vm.open).toEqual(false)
+ })
+
+ it('will close the dropdown and emit the search:blur event from onSearchBlur', () => {
+ const Select = selectWithProps()
+ const spy = jest.spyOn(Select.vm, '$emit')
+
+ Select.vm.open = true
+ Select.vm.onSearchBlur()
+
+ expect(Select.vm.open).toEqual(false)
+ expect(spy).toHaveBeenCalledWith('search:blur')
+ })
+
+ it('will open the dropdown and emit the search:focus event from onSearchFocus', () => {
+ const Select = selectWithProps()
+ const spy = jest.spyOn(Select.vm, '$emit')
+
+ Select.vm.onSearchFocus()
+
+ expect(Select.vm.open).toEqual(true)
+ expect(spy).toHaveBeenCalledWith('search:focus')
+ })
+
+ it('will close the dropdown on escape, if search is empty', () => {
+ const Select = selectWithProps()
+ const spy = jest.spyOn(Select.vm.$refs.search, 'blur')
+
+ Select.vm.open = true
+ Select.vm.onEscape()
+
+ expect(spy).toHaveBeenCalled()
+ })
+
+ it('should remove existing search text on escape keydown', () => {
+ const Select = selectWithProps({
+ value: [{ label: 'one' }],
+ options: [{ label: 'one' }],
+ })
+
+ Select.vm.search = 'foo'
Select.find('.vs__search').trigger('keydown.esc')
- expect(Select.vm.search).toEqual("");
- });
+ expect(Select.vm.search).toEqual('')
+ })
- it("should have an open class when dropdown is active", () => {
- const Select = selectWithProps();
+ it('should have an open class when dropdown is active', () => {
+ const Select = selectWithProps()
- expect(Select.vm.stateClasses['vs--open']).toEqual(false);
+ expect(Select.vm.stateClasses['vs--open']).toEqual(false)
- Select.vm.open = true;
- expect(Select.vm.stateClasses['vs--open']).toEqual(true);
- });
+ Select.vm.open = true
+ expect(Select.vm.stateClasses['vs--open']).toEqual(true)
+ })
- it("should not display the dropdown if noDrop is true", async () => {
+ it('should not display the dropdown if noDrop is true', async () => {
const Select = selectWithProps({
noDrop: true,
- });
+ })
- Select.vm.toggleDropdown(clickEvent(Select.vm.$refs.search));
+ Select.vm.toggleDropdown(clickEvent(Select.vm.$refs.search))
- expect(Select.vm.open).toEqual(true);
- await Select.vm.$nextTick();
+ expect(Select.vm.open).toEqual(true)
+ await Select.vm.$nextTick()
- expect(Select.contains('.vs__dropdown-menu')).toBeFalsy();
- expect(Select.contains('.vs__dropdown-option')).toBeFalsy();
- expect(Select.contains('.vs__no-options')).toBeFalsy();
- expect(Select.vm.stateClasses['vs--open']).toBeFalsy();
- });
+ expect(Select.contains('.vs__dropdown-menu')).toBeFalsy()
+ expect(Select.contains('.vs__dropdown-option')).toBeFalsy()
+ expect(Select.contains('.vs__no-options')).toBeFalsy()
+ expect(Select.vm.stateClasses['vs--open']).toBeFalsy()
+ })
- it("should hide the open indicator if noDrop is true", () => {
+ it('should hide the open indicator if noDrop is true', () => {
const Select = selectWithProps({
noDrop: true,
- });
- expect(Select.contains(OpenIndicator)).toBeFalsy();
- });
+ })
+ expect(Select.contains(OpenIndicator)).toBeFalsy()
+ })
- it("should not add the searchable state class when noDrop is true", () => {
+ it('should not add the searchable state class when noDrop is true', () => {
const Select = selectWithProps({
noDrop: true,
- });
- expect(Select.classes('vs--searchable')).toBeFalsy();
- });
+ })
+ expect(Select.classes('vs--searchable')).toBeFalsy()
+ })
- it("should not add the searching state class when noDrop is true", () => {
+ it('should not add the searching state class when noDrop is true', () => {
const Select = selectWithProps({
noDrop: true,
- });
+ })
- Select.vm.search = 'Canada';
+ Select.vm.search = 'Canada'
- expect(Select.classes('vs--searching')).toBeFalsy();
- });
+ expect(Select.classes('vs--searching')).toBeFalsy()
+ })
- it("can be opened with dropdownShouldOpen", () => {
+ it('can be opened with dropdownShouldOpen', () => {
const Select = selectWithProps({
noDrop: true,
dropdownShouldOpen: () => true,
- options: ['one']
- });
+ options: ['one'],
+ })
- expect(Select.classes('vs--open')).toBeTruthy();
- expect(Select.find('.vs__dropdown-menu li')).toBeTruthy();
+ expect(Select.classes('vs--open')).toBeTruthy()
+ expect(Select.find('.vs__dropdown-menu li')).toBeTruthy()
})
-});
+})
diff --git a/tests/unit/Filtering.spec.js b/tests/unit/Filtering.spec.js
index 05bff8b..0b19ca2 100755
--- a/tests/unit/Filtering.spec.js
+++ b/tests/unit/Filtering.spec.js
@@ -1,86 +1,86 @@
-import { shallowMount } from "@vue/test-utils";
-import VueSelect from "../../src/components/Select";
+import { shallowMount } from '@vue/test-utils'
+import VueSelect from '../../src/components/Select'
-describe("Filtering Options", () => {
+describe('Filtering Options', () => {
it("should update the search value when the input element receives the 'input' event", () => {
const Select = shallowMount(VueSelect, {
- propsData: { options: ["foo", "bar", "baz"] }
- });
-
- const input = Select.find('.vs__search');
+ propsData: { options: ['foo', 'bar', 'baz'] },
+ })
+
+ const input = Select.find('.vs__search')
input.element.value = 'a'
input.trigger('input')
- expect(Select.vm.search).toEqual('a');
- });
+ expect(Select.vm.search).toEqual('a')
+ })
- it("should filter an array of strings", () => {
+ it('should filter an array of strings', () => {
const Select = shallowMount(VueSelect, {
- propsData: { options: ["foo", "bar", "baz"] }
- });
- Select.vm.search = "ba";
- expect(Select.vm.filteredOptions).toEqual(["bar", "baz"]);
- });
+ propsData: { options: ['foo', 'bar', 'baz'] },
+ })
+ Select.vm.search = 'ba'
+ expect(Select.vm.filteredOptions).toEqual(['bar', 'baz'])
+ })
- it("should not filter the array of strings if filterable is false", () => {
+ it('should not filter the array of strings if filterable is false', () => {
const Select = shallowMount(VueSelect, {
- propsData: { options: ["foo", "bar", "baz"], filterable: false }
- });
- Select.vm.search = "ba";
- expect(Select.vm.filteredOptions).toEqual(["foo", "bar", "baz"]);
- });
+ propsData: { options: ['foo', 'bar', 'baz'], filterable: false },
+ })
+ Select.vm.search = 'ba'
+ expect(Select.vm.filteredOptions).toEqual(['foo', 'bar', 'baz'])
+ })
- it("should filter without case-sensitivity", () => {
+ it('should filter without case-sensitivity', () => {
const Select = shallowMount(VueSelect, {
- propsData: { options: ["Foo", "Bar", "Baz"] }
- });
- Select.vm.search = "ba";
- expect(Select.vm.filteredOptions).toEqual(["Bar", "Baz"]);
- });
+ propsData: { options: ['Foo', 'Bar', 'Baz'] },
+ })
+ Select.vm.search = 'ba'
+ expect(Select.vm.filteredOptions).toEqual(['Bar', 'Baz'])
+ })
- it("can filter an array of objects based on the objects label key", () => {
+ it('can filter an array of objects based on the objects label key', () => {
const Select = shallowMount(VueSelect, {
propsData: {
- options: [{ label: "Foo" }, { label: "Bar" }, { label: "Baz" }]
- }
- });
- Select.vm.search = "ba";
+ options: [{ label: 'Foo' }, { label: 'Bar' }, { label: 'Baz' }],
+ },
+ })
+ Select.vm.search = 'ba'
expect(Select.vm.filteredOptions).toEqual([
- { label: "Bar" },
- { label: "Baz" }
- ]);
- });
+ { label: 'Bar' },
+ { label: 'Baz' },
+ ])
+ })
- it("can determine if a given option should match the current search text", () => {
+ it('can determine if a given option should match the current search text', () => {
const Select = shallowMount(VueSelect, {
propsData: {
- options: [{ label: "Aoo" }, { label: "Bar" }, { label: "Baz" }],
+ options: [{ label: 'Aoo' }, { label: 'Bar' }, { label: 'Baz' }],
filterBy: (option, label, search) =>
- label.match(new RegExp("^" + search, "i"))
- }
- });
+ label.match(new RegExp('^' + search, 'i')),
+ },
+ })
- Select.vm.search = "a";
- expect(Select.vm.filteredOptions).toEqual([{ label: "Aoo" }]);
- });
+ Select.vm.search = 'a'
+ expect(Select.vm.filteredOptions).toEqual([{ label: 'Aoo' }])
+ })
- it("can use a custom filtering method", () => {
+ it('can use a custom filtering method', () => {
const Select = shallowMount(VueSelect, {
propsData: {
- options: ["foo", "bar", "baz"],
- filterBy: (option, label) => label.includes("o")
- }
- });
- Select.vm.search = "a";
- expect(Select.vm.filteredOptions).toEqual(["foo"]);
- });
+ options: ['foo', 'bar', 'baz'],
+ filterBy: (option, label) => label.includes('o'),
+ },
+ })
+ Select.vm.search = 'a'
+ expect(Select.vm.filteredOptions).toEqual(['foo'])
+ })
- it("can filter arrays of numbers", () => {
+ it('can filter arrays of numbers', () => {
const Select = shallowMount(VueSelect, {
propsData: {
- options: [1, 5, 10]
- }
- });
- Select.vm.search = "1";
- expect(Select.vm.filteredOptions).toEqual([1, 10]);
- });
-});
+ options: [1, 5, 10],
+ },
+ })
+ Select.vm.search = '1'
+ expect(Select.vm.filteredOptions).toEqual([1, 10])
+ })
+})
diff --git a/tests/unit/Keydown.spec.js b/tests/unit/Keydown.spec.js
index 3a4e865..4e224a6 100644
--- a/tests/unit/Keydown.spec.js
+++ b/tests/unit/Keydown.spec.js
@@ -1,74 +1,70 @@
-import { mountDefault } from '../helpers';
+import { mountDefault } from '../helpers'
describe('Custom Keydown Handlers', () => {
-
it('can use the map-keydown prop to trigger custom behaviour', () => {
- const onKeyDown = jest.fn();
+ const onKeyDown = jest.fn()
const Select = mountDefault({
mapKeydown: (defaults, vm) => ({ ...defaults, 32: onKeyDown }),
- });
+ })
- Select.find({ ref: 'search' }).trigger('keydown.space');
+ Select.find({ ref: 'search' }).trigger('keydown.space')
- expect(onKeyDown.mock.calls.length).toBe(1);
- });
+ expect(onKeyDown.mock.calls.length).toBe(1)
+ })
it('selectOnKeyCodes should trigger a selection for custom keycodes', () => {
const Select = mountDefault({
selectOnKeyCodes: [32],
- });
+ })
- const spy = jest.spyOn(Select.vm, 'typeAheadSelect');
+ const spy = jest.spyOn(Select.vm, 'typeAheadSelect')
- Select.find({ ref: 'search' }).trigger('keydown.space');
+ Select.find({ ref: 'search' }).trigger('keydown.space')
- expect(spy).toHaveBeenCalledTimes(1);
- });
+ expect(spy).toHaveBeenCalledTimes(1)
+ })
it('even works when combining selectOnKeyCodes with map-keydown', () => {
- const onKeyDown = jest.fn();
+ const onKeyDown = jest.fn()
const Select = mountDefault({
mapKeydown: (defaults, vm) => ({ ...defaults, 32: onKeyDown }),
selectOnKeyCodes: [9],
- });
+ })
- const spy = jest.spyOn(Select.vm, 'typeAheadSelect');
+ const spy = jest.spyOn(Select.vm, 'typeAheadSelect')
- Select.find({ ref: 'search' }).trigger('keydown.space');
- expect(onKeyDown.mock.calls.length).toBe(1);
+ Select.find({ ref: 'search' }).trigger('keydown.space')
+ expect(onKeyDown.mock.calls.length).toBe(1)
- Select.find({ ref: 'search' }).trigger('keydown.tab');
- expect(spy).toHaveBeenCalledTimes(1);
- });
+ Select.find({ ref: 'search' }).trigger('keydown.tab')
+ expect(spy).toHaveBeenCalledTimes(1)
+ })
describe('CompositionEvent support', () => {
-
it('will not select a value with enter if the user is composing', () => {
- const Select = mountDefault();
- const spy = jest.spyOn(Select.vm, 'typeAheadSelect');
+ const Select = mountDefault()
+ const spy = jest.spyOn(Select.vm, 'typeAheadSelect')
- Select.find({ ref: 'search' }).trigger('compositionstart');
- Select.find({ ref: 'search' }).trigger('keydown.enter');
- expect(spy).toHaveBeenCalledTimes(0);
+ Select.find({ ref: 'search' }).trigger('compositionstart')
+ Select.find({ ref: 'search' }).trigger('keydown.enter')
+ expect(spy).toHaveBeenCalledTimes(0)
- Select.find({ ref: 'search' }).trigger('compositionend');
- Select.find({ ref: 'search' }).trigger('keydown.enter');
- expect(spy).toHaveBeenCalledTimes(1);
- });
+ Select.find({ ref: 'search' }).trigger('compositionend')
+ Select.find({ ref: 'search' }).trigger('keydown.enter')
+ expect(spy).toHaveBeenCalledTimes(1)
+ })
it('will not select a value with tab if the user is composing', () => {
- const Select = mountDefault({ selectOnTab: true });
- const spy = jest.spyOn(Select.vm, 'typeAheadSelect');
+ const Select = mountDefault({ selectOnTab: true })
+ const spy = jest.spyOn(Select.vm, 'typeAheadSelect')
- Select.find({ ref: 'search' }).trigger('compositionstart');
- Select.find({ ref: 'search' }).trigger('keydown.tab');
- expect(spy).toHaveBeenCalledTimes(0);
+ Select.find({ ref: 'search' }).trigger('compositionstart')
+ Select.find({ ref: 'search' }).trigger('keydown.tab')
+ expect(spy).toHaveBeenCalledTimes(0)
- Select.find({ ref: 'search' }).trigger('compositionend');
- Select.find({ ref: 'search' }).trigger('keydown.tab');
- expect(spy).toHaveBeenCalledTimes(1);
- });
-
- });
-
-});
+ Select.find({ ref: 'search' }).trigger('compositionend')
+ Select.find({ ref: 'search' }).trigger('keydown.tab')
+ expect(spy).toHaveBeenCalledTimes(1)
+ })
+ })
+})
diff --git a/tests/unit/Labels.spec.js b/tests/unit/Labels.spec.js
index 1cbe8ef..b6dbc99 100755
--- a/tests/unit/Labels.spec.js
+++ b/tests/unit/Labels.spec.js
@@ -1,57 +1,61 @@
-import VueSelect from "../../src/components/Select";
-import { shallowMount } from "@vue/test-utils";
-import { selectWithProps } from "../helpers";
+import VueSelect from '../../src/components/Select'
+import { shallowMount } from '@vue/test-utils'
+import { selectWithProps } from '../helpers'
-describe("Labels", () => {
- it("can generate labels using a custom label key", () => {
+describe('Labels', () => {
+ it('can generate labels using a custom label key', () => {
const Select = selectWithProps({
- options: [{ name: "Foo" }],
- label: "name",
- value: { name: "Foo" }
- });
- expect(Select.find(".vs__selected").text()).toBe("Foo");
- });
+ options: [{ name: 'Foo' }],
+ label: 'name',
+ value: { name: 'Foo' },
+ })
+ expect(Select.find('.vs__selected').text()).toBe('Foo')
+ })
- it("will console.warn when options contain objects without a valid label key", async () => {
- const spy = jest.spyOn(console, "warn").mockImplementation(() => {});
+ it('will console.warn when options contain objects without a valid label key', async () => {
+ const spy = jest.spyOn(console, 'warn').mockImplementation(() => {})
const Select = selectWithProps({
- options: [{}]
- });
+ options: [{}],
+ })
- Select.vm.open = true;
- await Select.vm.$nextTick();
+ Select.vm.open = true
+ await Select.vm.$nextTick()
expect(spy).toHaveBeenCalledWith(
'[vue-select warn]: Label key "option.label" does not exist in options object {}.' +
- "\nhttps://vue-select.org/api/props.html#getoptionlabel"
- );
- });
+ '\nhttps://vue-select.org/api/props.html#getoptionlabel'
+ )
+ })
- it("should display a placeholder if the value is empty", () => {
+ it('should display a placeholder if the value is empty', () => {
const Select = shallowMount(VueSelect, {
propsData: {
- options: ["one"]
+ options: ['one'],
},
attrs: {
- placeholder: "foo"
- }
- });
+ placeholder: 'foo',
+ },
+ })
- expect(Select.vm.searchPlaceholder).toEqual("foo");
- Select.vm.$data._value = "one";
- expect(Select.vm.searchPlaceholder).not.toBeDefined();
- });
+ expect(Select.vm.searchPlaceholder).toEqual('foo')
+ Select.vm.$data._value = 'one'
+ expect(Select.vm.searchPlaceholder).not.toBeDefined()
+ })
describe('getOptionLabel', () => {
it('will return undefined if the option lacks the label key', () => {
- const getOptionLabel = VueSelect.props.getOptionLabel.default.bind({ label: 'label' });
- expect(getOptionLabel({name: 'vue'})).toEqual(undefined);
- });
+ const getOptionLabel = VueSelect.props.getOptionLabel.default.bind({
+ label: 'label',
+ })
+ expect(getOptionLabel({ name: 'vue' })).toEqual(undefined)
+ })
it('will return a string value for a valid key', () => {
- const getOptionLabel = VueSelect.props.getOptionLabel.default.bind({ label: 'label' });
- expect(getOptionLabel({label: 'vue'})).toEqual('vue');
- });
+ const getOptionLabel = VueSelect.props.getOptionLabel.default.bind({
+ label: 'label',
+ })
+ expect(getOptionLabel({ label: 'vue' })).toEqual('vue')
+ })
/**
* this test fails because of a bug where Vue executes the default contents
@@ -60,22 +64,22 @@ describe("Labels", () => {
* @see https://github.com/vuejs/vue/pull/10229
*/
xit('will not call getOptionLabel if both scoped option slots are used and a filter is provided', () => {
- const spy = spyOn(VueSelect.props.getOptionLabel, 'default');
+ const spy = spyOn(VueSelect.props.getOptionLabel, 'default')
const Select = shallowMount(VueSelect, {
propsData: {
- options: [{name: 'one'}],
+ options: [{ name: 'one' }],
filter: () => {},
},
scopedSlots: {
- 'option': '{{ props.name }}',
+ option: '{{ props.name }}',
'selected-option': '{{ props.name }}',
},
- });
+ })
- Select.vm.select({name: 'one'});
+ Select.vm.select({ name: 'one' })
- expect(spy).toHaveBeenCalledTimes(0);
- expect(Select.find('.selected').exists()).toBeTruthy();
- });
- });
-});
+ expect(spy).toHaveBeenCalledTimes(0)
+ expect(Select.find('.selected').exists()).toBeTruthy()
+ })
+ })
+})
diff --git a/tests/unit/Layout.spec.js b/tests/unit/Layout.spec.js
index 9acbb0c..78c218d 100755
--- a/tests/unit/Layout.spec.js
+++ b/tests/unit/Layout.spec.js
@@ -1,30 +1,30 @@
-import { shallowMount } from "@vue/test-utils";
-import VueSelect from "../../src/components/Select";
+import { shallowMount } from '@vue/test-utils'
+import VueSelect from '../../src/components/Select'
-describe("Single value options", () => {
- it("should reset the search input on focus lost", () => {
- const Select = shallowMount(VueSelect);
- Select.vm.open = true;
+describe('Single value options', () => {
+ it('should reset the search input on focus lost', () => {
+ const Select = shallowMount(VueSelect)
+ Select.vm.open = true
- Select.vm.search = "t";
- expect(Select.vm.search).toEqual("t");
+ Select.vm.search = 't'
+ expect(Select.vm.search).toEqual('t')
- Select.vm.onSearchBlur();
- expect(Select.vm.search).toEqual("");
- });
+ Select.vm.onSearchBlur()
+ expect(Select.vm.search).toEqual('')
+ })
- it("should not reset the search input on focus lost when clearSearchOnSelect is false", () => {
+ it('should not reset the search input on focus lost when clearSearchOnSelect is false', () => {
const Select = shallowMount(VueSelect, {
- propsData: { value: "foo", clearSearchOnSelect: false }
- });
+ propsData: { value: 'foo', clearSearchOnSelect: false },
+ })
- expect(Select.vm.clearSearchOnSelect).toEqual(false);
+ expect(Select.vm.clearSearchOnSelect).toEqual(false)
- Select.vm.open = true;
- Select.vm.search = "t";
- expect(Select.vm.search).toEqual("t");
+ Select.vm.open = true
+ Select.vm.search = 't'
+ expect(Select.vm.search).toEqual('t')
- Select.vm.onSearchBlur();
- expect(Select.vm.search).toEqual("t");
- });
-});
+ Select.vm.onSearchBlur()
+ expect(Select.vm.search).toEqual('t')
+ })
+})
diff --git a/tests/unit/OptionComparator.spec.js b/tests/unit/OptionComparator.spec.js
index 0e4da48..a1c7848 100644
--- a/tests/unit/OptionComparator.spec.js
+++ b/tests/unit/OptionComparator.spec.js
@@ -1,31 +1,32 @@
-import Select from '../../src/components/Select';
+import Select from '../../src/components/Select'
describe('Comparing Options', () => {
-
const comparator = Select.methods.optionComparator.bind({
getOptionKey: Select.props.getOptionKey.default,
- });
+ })
it('can compare numbers', () => {
- expect(comparator(1, 2)).toBeFalsy();
- expect(comparator(1, 1)).toBeTruthy();
- });
+ expect(comparator(1, 2)).toBeFalsy()
+ expect(comparator(1, 1)).toBeTruthy()
+ })
it('can compare strings', () => {
- expect(comparator('one', 'one')).toBeTruthy();
- expect(comparator('one', 'two')).toBeFalsy();
- });
+ expect(comparator('one', 'one')).toBeTruthy()
+ expect(comparator('one', 'two')).toBeFalsy()
+ })
it('can compare objects', () => {
// compare ID keys
- expect(comparator({label: 'halo', id: 1}, {label: 'halo', id: 2}))
- .toBeFalsy();
+ expect(
+ comparator({ label: 'halo', id: 1 }, { label: 'halo', id: 2 })
+ ).toBeFalsy()
// compare objects
- expect(comparator({label: 'halo', value: 1}, {label: 'halo', value: 1}))
- .toBeTruthy();
+ expect(
+ comparator({ label: 'halo', value: 1 }, { label: 'halo', value: 1 })
+ ).toBeTruthy()
// compare objects with different orders
- expect(comparator({value: 1, label: 'halo'}, {label: 'halo', value: 1}))
- .toBeTruthy();
- });
-
-});
+ expect(
+ comparator({ value: 1, label: 'halo' }, { label: 'halo', value: 1 })
+ ).toBeTruthy()
+ })
+})
diff --git a/tests/unit/OptionKey.spec.js b/tests/unit/OptionKey.spec.js
index cbe40b2..a349b8a 100644
--- a/tests/unit/OptionKey.spec.js
+++ b/tests/unit/OptionKey.spec.js
@@ -1,25 +1,25 @@
-import Select from '../../src/components/Select.vue';
+import Select from '../../src/components/Select.vue'
describe('Serializing Option Keys', () => {
-
- const getOptionKey = Select.props.getOptionKey.default;
+ const getOptionKey = Select.props.getOptionKey.default
it('can serialize strings to a key', () => {
- expect(getOptionKey('vue')).toBe('vue');
- });
+ expect(getOptionKey('vue')).toBe('vue')
+ })
it('can serialize integers to a key', () => {
- expect(getOptionKey(1)).toBe(1);
- });
+ expect(getOptionKey(1)).toBe(1)
+ })
it('can serialize objects to a key', () => {
- expect(getOptionKey({label: 'vue'})).toBe('{"label":"vue"}');
- });
+ expect(getOptionKey({ label: 'vue' })).toBe('{"label":"vue"}')
+ })
it('will use an ID property if the object contains one', () => {
- expect(getOptionKey({id: 1})).toBe(1);
- expect(getOptionKey({id: 'one'})).toBe('one');
- expect(getOptionKey({id: {im: 'a nested object'}}))
- .toEqual({im: 'a nested object'});
- });
-});
+ expect(getOptionKey({ id: 1 })).toBe(1)
+ expect(getOptionKey({ id: 'one' })).toBe('one')
+ expect(getOptionKey({ id: { im: 'a nested object' } })).toEqual({
+ im: 'a nested object',
+ })
+ })
+})
diff --git a/tests/unit/ReactiveOptions.spec.js b/tests/unit/ReactiveOptions.spec.js
index f28320f..a010d3c 100755
--- a/tests/unit/ReactiveOptions.spec.js
+++ b/tests/unit/ReactiveOptions.spec.js
@@ -1,141 +1,163 @@
-import { mount, shallowMount } from '@vue/test-utils';
-import VueSelect from "../../src/components/Select";
-import { mountDefault } from '../helpers';
+import { mount, shallowMount } from '@vue/test-utils'
+import VueSelect from '../../src/components/Select'
+import { mountDefault } from '../helpers'
-describe("Reset on options change", () => {
- it("should not reset the selected value by default when the options property changes", () => {
+describe('Reset on options change', () => {
+ it('should not reset the selected value by default when the options property changes', () => {
const Select = shallowMount(VueSelect, {
- propsData: { options: ["one"] }
- });
+ propsData: { options: ['one'] },
+ })
- Select.vm.$data._value = 'one';
+ Select.vm.$data._value = 'one'
- Select.setProps({options: ["four", "five", "six"]});
- expect(Select.vm.selectedValue).toEqual(["one"]);
- });
+ Select.setProps({ options: ['four', 'five', 'six'] })
+ expect(Select.vm.selectedValue).toEqual(['one'])
+ })
describe('resetOnOptionsChange as a function', () => {
it('will yell at you if resetOnOptionsChange is not a function or boolean', () => {
- const spy = jest.spyOn(console, 'error').mockImplementation(() => {});
+ const spy = jest.spyOn(console, 'error').mockImplementation(() => {})
- mountDefault({resetOnOptionsChange: 1});
- expect(spy.mock.calls[0][0]).toContain('Invalid prop: custom validator check failed for prop "resetOnOptionsChange"')
+ mountDefault({ resetOnOptionsChange: 1 })
+ expect(spy.mock.calls[0][0]).toContain(
+ 'Invalid prop: custom validator check failed for prop "resetOnOptionsChange"'
+ )
- mountDefault({resetOnOptionsChange: 'one'});
- expect(spy.mock.calls[1][0]).toContain('Invalid prop: custom validator check failed for prop "resetOnOptionsChange"')
+ mountDefault({ resetOnOptionsChange: 'one' })
+ expect(spy.mock.calls[1][0]).toContain(
+ 'Invalid prop: custom validator check failed for prop "resetOnOptionsChange"'
+ )
- mountDefault({resetOnOptionsChange: []});
- expect(spy.mock.calls[2][0]).toContain('Invalid prop: custom validator check failed for prop "resetOnOptionsChange"')
+ mountDefault({ resetOnOptionsChange: [] })
+ expect(spy.mock.calls[2][0]).toContain(
+ 'Invalid prop: custom validator check failed for prop "resetOnOptionsChange"'
+ )
- mountDefault({resetOnOptionsChange: {}});
- expect(spy.mock.calls[3][0]).toContain('Invalid prop: custom validator check failed for prop "resetOnOptionsChange"')
- });
+ mountDefault({ resetOnOptionsChange: {} })
+ expect(spy.mock.calls[3][0]).toContain(
+ 'Invalid prop: custom validator check failed for prop "resetOnOptionsChange"'
+ )
+ })
it('should receive the new options, old options, and current value', async () => {
- let resetOnOptionsChange = jest.fn(option => option);
- const Select = mountDefault(
- {resetOnOptionsChange, options: ['bear'], value: 'selected'},
- );
+ let resetOnOptionsChange = jest.fn((option) => option)
+ const Select = mountDefault({
+ resetOnOptionsChange,
+ options: ['bear'],
+ value: 'selected',
+ })
- Select.setProps({options: ['lake', 'kite']});
- await Select.vm.$nextTick();
+ Select.setProps({ options: ['lake', 'kite'] })
+ await Select.vm.$nextTick()
- expect(resetOnOptionsChange).toHaveBeenCalledTimes(1);
- expect(resetOnOptionsChange)
- .toHaveBeenCalledWith(['lake', 'kite'], ['bear'], ['selected']);
- });
+ expect(resetOnOptionsChange).toHaveBeenCalledTimes(1)
+ expect(resetOnOptionsChange).toHaveBeenCalledWith(
+ ['lake', 'kite'],
+ ['bear'],
+ ['selected']
+ )
+ })
it('should allow resetOnOptionsChange to be a function that returns true', async () => {
- let resetOnOptionsChange = () => true;
+ let resetOnOptionsChange = () => true
const Select = shallowMount(VueSelect, {
- propsData: {resetOnOptionsChange, options: ['one'], value: 'one'},
- });
- const spy = jest.spyOn(Select.vm, 'clearSelection');
+ propsData: { resetOnOptionsChange, options: ['one'], value: 'one' },
+ })
+ const spy = jest.spyOn(Select.vm, 'clearSelection')
- Select.setProps({options: ['one', 'two']});
- await Select.vm.$nextTick();
+ Select.setProps({ options: ['one', 'two'] })
+ await Select.vm.$nextTick()
- expect(spy).toHaveBeenCalledTimes(1);
- });
+ expect(spy).toHaveBeenCalledTimes(1)
+ })
it('should allow resetOnOptionsChange to be a function that returns false', () => {
- let resetOnOptionsChange = () => false;
+ let resetOnOptionsChange = () => false
const Select = shallowMount(VueSelect, {
- propsData: {resetOnOptionsChange, options: ['one'], value: 'one'},
- });
- const spy = jest.spyOn(Select.vm, 'clearSelection');
+ propsData: { resetOnOptionsChange, options: ['one'], value: 'one' },
+ })
+ const spy = jest.spyOn(Select.vm, 'clearSelection')
- Select.setProps({options: ['one', 'two']});
- expect(spy).not.toHaveBeenCalled();
- });
+ Select.setProps({ options: ['one', 'two'] })
+ expect(spy).not.toHaveBeenCalled()
+ })
it('should reset the options if the selectedValue does not exist in the new options', async () => {
- let resetOnOptionsChange = (options, old, val) => val.some(val => options.includes(val));
+ let resetOnOptionsChange = (options, old, val) =>
+ val.some((val) => options.includes(val))
const Select = shallowMount(VueSelect, {
- propsData: {resetOnOptionsChange, options: ['one'], value: 'one'},
- });
- const spy = jest.spyOn(Select.vm, 'clearSelection');
+ propsData: { resetOnOptionsChange, options: ['one'], value: 'one' },
+ })
+ const spy = jest.spyOn(Select.vm, 'clearSelection')
- Select.setProps({options: ['one', 'two']});
- await Select.vm.$nextTick();
+ Select.setProps({ options: ['one', 'two'] })
+ await Select.vm.$nextTick()
- expect(Select.vm.selectedValue).toEqual(['one']);
+ expect(Select.vm.selectedValue).toEqual(['one'])
- Select.setProps({options: ['two']});
- await Select.vm.$nextTick();
+ Select.setProps({ options: ['two'] })
+ await Select.vm.$nextTick()
- expect(spy).toHaveBeenCalledTimes(1);
- });
- });
+ expect(spy).toHaveBeenCalledTimes(1)
+ })
+ })
- it("should reset the selected value when the options property changes", async () => {
+ it('should reset the selected value when the options property changes', async () => {
const Select = shallowMount(VueSelect, {
- propsData: { resetOnOptionsChange: true, options: ["one"] }
- });
+ propsData: { resetOnOptionsChange: true, options: ['one'] },
+ })
- Select.vm.$data._value = 'one';
+ Select.vm.$data._value = 'one'
- Select.setProps({options: ["four", "five", "six"]});
- await Select.vm.$nextTick();
+ Select.setProps({ options: ['four', 'five', 'six'] })
+ await Select.vm.$nextTick()
- expect(Select.vm.selectedValue).toEqual([]);
- });
+ expect(Select.vm.selectedValue).toEqual([])
+ })
- it("should return correct selected value when the options property changes and a new option matches", async () => {
+ it('should return correct selected value when the options property changes and a new option matches', async () => {
const Select = shallowMount(VueSelect, {
- propsData: { value: "one", options: [], reduce(option) { return option.value } }
- });
+ propsData: {
+ value: 'one',
+ options: [],
+ reduce(option) {
+ return option.value
+ },
+ },
+ })
- Select.setProps({options: [{ label: "oneLabel", value: "one" }]});
- await Select.vm.$nextTick();
+ Select.setProps({ options: [{ label: 'oneLabel', value: 'one' }] })
+ await Select.vm.$nextTick()
- expect(Select.vm.selectedValue).toEqual([{ label: "oneLabel", value: "one" }]);
- });
+ expect(Select.vm.selectedValue).toEqual([
+ { label: 'oneLabel', value: 'one' },
+ ])
+ })
it('clearSearchOnBlur returns false when multiple is true', () => {
- const Select = mountDefault({});
- let clearSearchOnBlur = jest.spyOn(Select.vm, 'clearSearchOnBlur');
- Select.find({ref: 'search'}).trigger('click');
- Select.setData({search: 'one'});
- Select.find({ref: 'search'}).trigger('blur');
+ const Select = mountDefault({})
+ let clearSearchOnBlur = jest.spyOn(Select.vm, 'clearSearchOnBlur')
+ Select.find({ ref: 'search' }).trigger('click')
+ Select.setData({ search: 'one' })
+ Select.find({ ref: 'search' }).trigger('blur')
- expect(clearSearchOnBlur).toHaveBeenCalledTimes(1);
+ expect(clearSearchOnBlur).toHaveBeenCalledTimes(1)
expect(clearSearchOnBlur).toHaveBeenCalledWith({
clearSearchOnSelect: true,
multiple: false,
- });
- expect(Select.vm.search).toBe('');
- });
+ })
+ expect(Select.vm.search).toBe('')
+ })
it('clearSearchOnBlur accepts a function', () => {
- let clearSearchOnBlur = jest.fn(() => false);
- const Select = mountDefault({clearSearchOnBlur});
+ let clearSearchOnBlur = jest.fn(() => false)
+ const Select = mountDefault({ clearSearchOnBlur })
- Select.find({ref: 'search'}).trigger('click');
- Select.setData({search: 'one'});
- Select.find({ref: 'search'}).trigger('blur');
+ Select.find({ ref: 'search' }).trigger('click')
+ Select.setData({ search: 'one' })
+ Select.find({ ref: 'search' }).trigger('blur')
- expect(clearSearchOnBlur).toHaveBeenCalledTimes(1);
- expect(Select.vm.search).toBe('one');
- });
-});
+ expect(clearSearchOnBlur).toHaveBeenCalledTimes(1)
+ expect(Select.vm.search).toBe('one')
+ })
+})
diff --git a/tests/unit/Reduce.spec.js b/tests/unit/Reduce.spec.js
index de1a24d..032e010 100755
--- a/tests/unit/Reduce.spec.js
+++ b/tests/unit/Reduce.spec.js
@@ -1,127 +1,133 @@
-import { mount, shallowMount } from "@vue/test-utils";
-import VueSelect from "../../src/components/Select";
+import { mount, shallowMount } from '@vue/test-utils'
+import VueSelect from '../../src/components/Select'
-describe("When reduce prop is defined", () => {
- it("can accept an array of objects and pre-selected value (single)", () => {
+describe('When reduce prop is defined', () => {
+ it('can accept an array of objects and pre-selected value (single)', () => {
const Select = shallowMount(VueSelect, {
propsData: {
- reduce: option => option.value,
- value: "foo",
- options: [{ label: "This is Foo", value: "foo" }]
- }
- });
- expect(Select.vm.selectedValue).toEqual([{ label: "This is Foo", value: "foo" }]);
- });
+ reduce: (option) => option.value,
+ value: 'foo',
+ options: [{ label: 'This is Foo', value: 'foo' }],
+ },
+ })
+ expect(Select.vm.selectedValue).toEqual([
+ { label: 'This is Foo', value: 'foo' },
+ ])
+ })
- it("can determine if an object is pre-selected", () => {
+ it('can determine if an object is pre-selected', () => {
const Select = shallowMount(VueSelect, {
propsData: {
- reduce: option => option.id,
- value: "foo",
+ reduce: (option) => option.id,
+ value: 'foo',
options: [
{
- id: "foo",
- label: "This is Foo"
- }
- ]
- }
- });
+ id: 'foo',
+ label: 'This is Foo',
+ },
+ ],
+ },
+ })
expect(
Select.vm.isOptionSelected({
- id: "foo",
- label: "This is Foo"
+ id: 'foo',
+ label: 'This is Foo',
})
- ).toEqual(true);
- });
+ ).toEqual(true)
+ })
it('can determine if an object is selected after its been chosen', () => {
- const Select = shallowMount(VueSelect, {
- propsData: {
- reduce: option => option.id,
- options: [{id: 'foo', label: 'FooBar'}],
- },
- });
+ const Select = shallowMount(VueSelect, {
+ propsData: {
+ reduce: (option) => option.id,
+ options: [{ id: 'foo', label: 'FooBar' }],
+ },
+ })
- Select.vm.select({id: 'foo', label: 'FooBar'});
+ Select.vm.select({ id: 'foo', label: 'FooBar' })
- expect(Select.vm.isOptionSelected({
+ expect(
+ Select.vm.isOptionSelected({
id: 'foo',
label: 'This is FooBar',
- })).toEqual(true);
- });
+ })
+ ).toEqual(true)
+ })
- it("can accept an array of objects and pre-selected values (multiple)", () => {
+ it('can accept an array of objects and pre-selected values (multiple)', () => {
const Select = shallowMount(VueSelect, {
propsData: {
multiple: true,
- reduce: option => option.value,
- value: ["foo"],
+ reduce: (option) => option.value,
+ value: ['foo'],
options: [
- { label: "This is Foo", value: "foo" },
- { label: "This is Bar", value: "bar" }
- ]
- }
- });
+ { label: 'This is Foo', value: 'foo' },
+ { label: 'This is Bar', value: 'bar' },
+ ],
+ },
+ })
- expect(Select.vm.selectedValue).toEqual([{ label: "This is Foo", value: "foo" }]);
- });
+ expect(Select.vm.selectedValue).toEqual([
+ { label: 'This is Foo', value: 'foo' },
+ ])
+ })
- it("can deselect a pre-selected object", () => {
+ it('can deselect a pre-selected object', () => {
const Select = shallowMount(VueSelect, {
propsData: {
multiple: true,
- reduce: option => option.value,
+ reduce: (option) => option.value,
options: [
- { label: "This is Foo", value: "foo" },
- { label: "This is Bar", value: "bar" }
- ]
- }
- });
+ { label: 'This is Foo', value: 'foo' },
+ { label: 'This is Bar', value: 'bar' },
+ ],
+ },
+ })
- Select.vm.$data._value = ['foo', 'bar'];
+ Select.vm.$data._value = ['foo', 'bar']
- Select.vm.deselect("foo");
- expect(Select.vm.selectedValue).toEqual(["bar"]);
- });
+ Select.vm.deselect('foo')
+ expect(Select.vm.selectedValue).toEqual(['bar'])
+ })
- it("can deselect an option when multiple is false", () => {
+ it('can deselect an option when multiple is false', () => {
const Select = shallowMount(VueSelect, {
propsData: {
- reduce: option => option.value,
+ reduce: (option) => option.value,
options: [
- { label: "This is Foo", value: "foo" },
- { label: "This is Bar", value: "bar" }
- ]
- }
- });
+ { label: 'This is Foo', value: 'foo' },
+ { label: 'This is Bar', value: 'bar' },
+ ],
+ },
+ })
- Select.vm.deselect("foo");
- expect(Select.vm.selectedValue).toEqual([]);
- });
+ Select.vm.deselect('foo')
+ expect(Select.vm.selectedValue).toEqual([])
+ })
- it("can use v-model syntax for a two way binding to a parent component", async () => {
+ it('can use v-model syntax for a two way binding to a parent component', async () => {
const Parent = mount({
data: () => ({
- reduce: option => option.value,
- current: "foo",
+ reduce: (option) => option.value,
+ current: 'foo',
options: [
- { label: "This is Foo", value: "foo" },
- { label: "This is Bar", value: "bar" },
- { label: "This is Baz", value: "baz" }
- ]
+ { label: 'This is Foo', value: 'foo' },
+ { label: 'This is Bar', value: 'bar' },
+ { label: 'This is Baz', value: 'baz' },
+ ],
}),
- components: { "v-select": VueSelect },
+ components: { 'v-select': VueSelect },
computed: {
value: {
get() {
- return this.current;
+ return this.current
},
set(value) {
- if (value == 'baz') return;
- this.current = value;
- }
- }
+ if (value == 'baz') return
+ this.current = value
+ },
+ },
},
template: `
{
:reduce="option => option.value"
:options="options"
/>
- `
- });
- const Select = Parent.vm.$children[0];
+ `,
+ })
+ const Select = Parent.vm.$children[0]
- expect(Select.value).toEqual("foo");
- expect(Select.selectedValue).toEqual([{ label: "This is Foo", value: "foo" }]);
+ expect(Select.value).toEqual('foo')
+ expect(Select.selectedValue).toEqual([
+ { label: 'This is Foo', value: 'foo' },
+ ])
- Select.select({ label: "This is Bar", value: "bar" });
- await Select.$nextTick();
- expect(Parent.vm.value).toEqual("bar");
- expect(Select.selectedValue).toEqual([{ label: "This is Bar", value: "bar" }]);
+ Select.select({ label: 'This is Bar', value: 'bar' })
+ await Select.$nextTick()
+ expect(Parent.vm.value).toEqual('bar')
+ expect(Select.selectedValue).toEqual([
+ { label: 'This is Bar', value: 'bar' },
+ ])
// Parent denies to set baz
- Select.select({ label: "This is Baz", value: "baz" });
- await Select.$nextTick();
- expect(Select.selectedValue).toEqual([{ label: "This is Bar", value: "bar" }]);
- expect(Parent.vm.value).toEqual('bar');
- });
+ Select.select({ label: 'This is Baz', value: 'baz' })
+ await Select.$nextTick()
+ expect(Select.selectedValue).toEqual([
+ { label: 'This is Bar', value: 'bar' },
+ ])
+ expect(Parent.vm.value).toEqual('bar')
+ })
- it("can generate labels using a custom label key", () => {
+ it('can generate labels using a custom label key', () => {
const Select = shallowMount(VueSelect, {
propsData: {
multiple: true,
- reduce: option => option.value,
- value: ["CA"],
- label: "name",
- options: [{ value: "CA", name: "Canada" }, { value: "US", name: "United States" }]
- }
- });
+ reduce: (option) => option.value,
+ value: ['CA'],
+ label: 'name',
+ options: [
+ { value: 'CA', name: 'Canada' },
+ { value: 'US', name: 'United States' },
+ ],
+ },
+ })
- expect(Select.find(".vs__selected").text()).toContain("Canada");
- });
+ expect(Select.find('.vs__selected').text()).toContain('Canada')
+ })
- it("can find the original option within this.options", () => {
- const optionToFind = { id: 1, label: "Foo" };
+ it('can find the original option within this.options', () => {
+ const optionToFind = { id: 1, label: 'Foo' }
const Select = shallowMount(VueSelect, {
propsData: {
- reduce: option => option.id,
- options: [optionToFind, { id: 2, label: "Bar" }]
- }
- });
+ reduce: (option) => option.id,
+ options: [optionToFind, { id: 2, label: 'Bar' }],
+ },
+ })
- expect(Select.vm.findOptionFromReducedValue(1)).toEqual(optionToFind);
+ expect(Select.vm.findOptionFromReducedValue(1)).toEqual(optionToFind)
expect(Select.vm.findOptionFromReducedValue(optionToFind)).toEqual(
optionToFind
- );
- });
+ )
+ })
it('can work with falsey values', () => {
- const option = {value: 0, label: 'No'};
+ const option = { value: 0, label: 'No' }
const Select = shallowMount(VueSelect, {
propsData: {
- reduce: option => option.value,
- options: [option, {value: 1, label: 'Yes'}],
+ reduce: (option) => option.value,
+ options: [option, { value: 1, label: 'Yes' }],
value: 0,
},
- });
+ })
- expect(Select.vm.findOptionFromReducedValue(option)).toEqual(option);
- expect(Select.vm.selectedValue).toEqual([option]);
- });
+ expect(Select.vm.findOptionFromReducedValue(option)).toEqual(option)
+ expect(Select.vm.selectedValue).toEqual([option])
+ })
it('works with null values', () => {
- const option = {value: null, label: 'No'};
+ const option = { value: null, label: 'No' }
const Select = shallowMount(VueSelect, {
propsData: {
- reduce: option => option.value,
- options: [option, {value: 1, label: 'Yes'}],
+ reduce: (option) => option.value,
+ options: [option, { value: 1, label: 'Yes' }],
value: null,
},
- });
+ })
- expect(Select.vm.findOptionFromReducedValue(option)).toEqual(option);
- expect(Select.vm.selectedValue).toEqual([option]);
- });
+ expect(Select.vm.findOptionFromReducedValue(option)).toEqual(option)
+ expect(Select.vm.selectedValue).toEqual([option])
+ })
- describe("And when a reduced option is a nested object", () => {
- it("can determine if an object is pre-selected", () => {
- const nestedOption = { value: { nested: true }, label: "foo" };
+ describe('And when a reduced option is a nested object', () => {
+ it('can determine if an object is pre-selected', () => {
+ const nestedOption = { value: { nested: true }, label: 'foo' }
const Select = shallowMount(VueSelect, {
propsData: {
- reduce: option => option.value,
+ reduce: (option) => option.value,
value: {
- nested: true
+ nested: true,
},
- options: [nestedOption]
- }
- });
+ options: [nestedOption],
+ },
+ })
- expect(Select.vm.selectedValue).toEqual([nestedOption]);
- });
+ expect(Select.vm.selectedValue).toEqual([nestedOption])
+ })
- it("can determine if an object is selected after it is chosen", () => {
- const nestedOption = { value: { nested: true }, label: "foo" };
+ it('can determine if an object is selected after it is chosen', () => {
+ const nestedOption = { value: { nested: true }, label: 'foo' }
const Select = shallowMount(VueSelect, {
propsData: {
- reduce: option => option.value,
- options: [nestedOption]
- }
- });
+ reduce: (option) => option.value,
+ options: [nestedOption],
+ },
+ })
- Select.vm.select(nestedOption);
- expect(Select.vm.isOptionSelected(nestedOption)).toEqual(true);
- });
+ Select.vm.select(nestedOption)
+ expect(Select.vm.isOptionSelected(nestedOption)).toEqual(true)
+ })
+ })
- });
-
- it("reacts correctly when value property changes", async () => {
- const optionToChangeTo = { id: 1, label: "Foo" };
+ it('reacts correctly when value property changes', async () => {
+ const optionToChangeTo = { id: 1, label: 'Foo' }
const Select = shallowMount(VueSelect, {
propsData: {
value: 2,
- reduce: option => option.id,
- options: [optionToChangeTo, { id: 2, label: "Bar" }]
- }
- });
+ reduce: (option) => option.id,
+ options: [optionToChangeTo, { id: 2, label: 'Bar' }],
+ },
+ })
- Select.setProps({ value: optionToChangeTo.id });
- await Select.vm.$nextTick();
+ Select.setProps({ value: optionToChangeTo.id })
+ await Select.vm.$nextTick()
- expect(Select.vm.selectedValue).toEqual([optionToChangeTo]);
- });
+ expect(Select.vm.selectedValue).toEqual([optionToChangeTo])
+ })
describe('Reducing Tags', () => {
it('tracks values that have been created by the user', async () => {
const Parent = mount({
- data: () => ({selected: null, options: []}),
+ data: () => ({ selected: null, options: [] }),
template: `
{
:create-option="label => ({ label, value: -1 })"
/>
`,
- components: {'v-select': VueSelect},
- });
- const Select = Parent.vm.$children[0];
+ components: { 'v-select': VueSelect },
+ })
+ const Select = Parent.vm.$children[0]
// When
- Select.$refs.search.focus();
- await Select.$nextTick();
+ Select.$refs.search.focus()
+ await Select.$nextTick()
- Select.search = 'hello';
- await Select.$nextTick();
+ Select.search = 'hello'
+ await Select.$nextTick()
- Select.typeAheadSelect();
- await Select.$nextTick();
+ Select.typeAheadSelect()
+ await Select.$nextTick()
// Then
- expect(Select.selectedValue).toEqual([{label: 'hello', value: -1}]);
- expect(Select.$refs.selectedOptions.textContent.trim()).toEqual('hello');
- expect(Parent.vm.selected).toEqual(-1);
- });
- });
-});
+ expect(Select.selectedValue).toEqual([{ label: 'hello', value: -1 }])
+ expect(Select.$refs.selectedOptions.textContent.trim()).toEqual('hello')
+ expect(Parent.vm.selected).toEqual(-1)
+ })
+ })
+})
diff --git a/tests/unit/Selectable.spec.js b/tests/unit/Selectable.spec.js
index c75c086..bfa0449 100644
--- a/tests/unit/Selectable.spec.js
+++ b/tests/unit/Selectable.spec.js
@@ -1,59 +1,59 @@
-import { selectWithProps } from "../helpers";
+import { selectWithProps } from '../helpers'
-describe("Selectable prop", () => {
- it("should select selectable option if clicked", async () => {
+describe('Selectable prop', () => {
+ it('should select selectable option if clicked', async () => {
const Select = selectWithProps({
- options: ["one", "two", "three"],
- selectable: (option) => option === "one"
- });
+ options: ['one', 'two', 'three'],
+ selectable: (option) => option === 'one',
+ })
- Select.vm.$data.open = true;
- await Select.vm.$nextTick();
+ Select.vm.$data.open = true
+ await Select.vm.$nextTick()
- Select.find(".vs__dropdown-menu li:first-child").trigger("mousedown");
+ Select.find('.vs__dropdown-menu li:first-child').trigger('mousedown')
- await Select.vm.$nextTick();
- expect(Select.vm.selectedValue).toEqual(["one"]);
+ await Select.vm.$nextTick()
+ expect(Select.vm.selectedValue).toEqual(['one'])
})
- it("should not select not selectable option if clicked", async () => {
+ it('should not select not selectable option if clicked', async () => {
const Select = selectWithProps({
- options: ["one", "two", "three"],
- selectable: (option) => option === "one"
- });
+ options: ['one', 'two', 'three'],
+ selectable: (option) => option === 'one',
+ })
- Select.vm.$data.open = true;
- await Select.vm.$nextTick();
+ Select.vm.$data.open = true
+ await Select.vm.$nextTick()
- Select.find(".vs__dropdown-menu li:last-child").trigger("mousedown");
- await Select.vm.$nextTick();
+ Select.find('.vs__dropdown-menu li:last-child').trigger('mousedown')
+ await Select.vm.$nextTick()
- expect(Select.vm.selectedValue).toEqual([]);
- });
-
- it("should skip non-selectable option on down arrow keyDown", () => {
- const Select = selectWithProps({
- options: ["one", "two", "three"],
- selectable: (option) => option !== "two"
- });
-
- Select.vm.typeAheadPointer = 1;
-
- Select.find({ ref: "search" }).trigger("keydown.down");
-
- expect(Select.vm.typeAheadPointer).toEqual(2);
+ expect(Select.vm.selectedValue).toEqual([])
})
- it("should skip non-selectable option on up arrow keyDown", () => {
+ it('should skip non-selectable option on down arrow keyDown', () => {
const Select = selectWithProps({
- options: ["one", "two", "three"],
- selectable: (option) => option !== "two"
- });
+ options: ['one', 'two', 'three'],
+ selectable: (option) => option !== 'two',
+ })
- Select.vm.typeAheadPointer = 2;
+ Select.vm.typeAheadPointer = 1
- Select.find({ ref: "search" }).trigger("keydown.up");
+ Select.find({ ref: 'search' }).trigger('keydown.down')
- expect(Select.vm.typeAheadPointer).toEqual(0);
+ expect(Select.vm.typeAheadPointer).toEqual(2)
+ })
+
+ it('should skip non-selectable option on up arrow keyDown', () => {
+ const Select = selectWithProps({
+ options: ['one', 'two', 'three'],
+ selectable: (option) => option !== 'two',
+ })
+
+ Select.vm.typeAheadPointer = 2
+
+ Select.find({ ref: 'search' }).trigger('keydown.up')
+
+ expect(Select.vm.typeAheadPointer).toEqual(0)
})
})
diff --git a/tests/unit/Selecting.spec.js b/tests/unit/Selecting.spec.js
index a9eb33c..02ad976 100755
--- a/tests/unit/Selecting.spec.js
+++ b/tests/unit/Selecting.spec.js
@@ -1,303 +1,322 @@
-import { mount, shallowMount } from "@vue/test-utils";
-import VueSelect from "../../src/components/Select.vue";
-import { mountDefault } from '../helpers';
+import { mount, shallowMount } from '@vue/test-utils'
+import VueSelect from '../../src/components/Select.vue'
+import { mountDefault } from '../helpers'
-describe("VS - Selecting Values", () => {
- let defaultProps;
+describe('VS - Selecting Values', () => {
+ let defaultProps
beforeEach(() => {
defaultProps = {
- value: "one",
- options: ["one", "two", "three"]
- };
- });
+ value: 'one',
+ options: ['one', 'two', 'three'],
+ }
+ })
- it("can accept an array with pre-selected values", () => {
+ it('can accept an array with pre-selected values', () => {
const Select = shallowMount(VueSelect, {
- propsData: defaultProps
- });
- expect(Select.selectedValue).toEqual(Select.value);
- });
+ propsData: defaultProps,
+ })
+ expect(Select.selectedValue).toEqual(Select.value)
+ })
- it("can accept an array of objects and pre-selected value (single)", () => {
+ it('can accept an array of objects and pre-selected value (single)', () => {
const Select = shallowMount(VueSelect, {
propsData: {
- value: { label: "This is Foo", value: "foo" },
+ value: { label: 'This is Foo', value: 'foo' },
options: [
- { label: "This is Foo", value: "foo" },
- { label: "This is Bar", value: "bar" }
- ]
- }
- });
- expect(Select.selectedValue).toEqual(Select.value);
- });
+ { label: 'This is Foo', value: 'foo' },
+ { label: 'This is Bar', value: 'bar' },
+ ],
+ },
+ })
+ expect(Select.selectedValue).toEqual(Select.value)
+ })
- it("can accept an array of objects and pre-selected values (multiple)", () => {
+ it('can accept an array of objects and pre-selected values (multiple)', () => {
const Select = shallowMount(VueSelect, {
propsData: {
value: [
- { label: "This is Foo", value: "foo" },
- { label: "This is Bar", value: "bar" }
+ { label: 'This is Foo', value: 'foo' },
+ { label: 'This is Bar', value: 'bar' },
],
options: [
- { label: "This is Foo", value: "foo" },
- { label: "This is Bar", value: "bar" }
- ]
+ { label: 'This is Foo', value: 'foo' },
+ { label: 'This is Bar', value: 'bar' },
+ ],
},
- multiple: true
- });
+ multiple: true,
+ })
- expect(Select.selectedValue).toEqual(Select.value);
- });
+ expect(Select.selectedValue).toEqual(Select.value)
+ })
- it("can select an option on tab", () => {
+ it('can select an option on tab', () => {
const Select = shallowMount(VueSelect, {
propsData: {
- selectOnTab: true
- }
- });
+ selectOnTab: true,
+ },
+ })
- const spy = jest.spyOn(Select.vm, "typeAheadSelect");
+ const spy = jest.spyOn(Select.vm, 'typeAheadSelect')
- Select.find({ ref: "search" }).trigger("keydown.tab");
+ Select.find({ ref: 'search' }).trigger('keydown.tab')
- expect(spy).toHaveBeenCalledWith();
- });
+ expect(spy).toHaveBeenCalledWith()
+ })
- it("can deselect a pre-selected object", () => {
+ it('can deselect a pre-selected object', () => {
const Select = shallowMount(VueSelect, {
propsData: {
multiple: true,
options: [
- { label: "This is Foo", value: "foo" },
- { label: "This is Bar", value: "bar" }
- ]
- }
- });
+ { label: 'This is Foo', value: 'foo' },
+ { label: 'This is Bar', value: 'bar' },
+ ],
+ },
+ })
Select.vm.$data._value = [
- { label: "This is Foo", value: "foo" },
- { label: "This is Bar", value: "bar" }
- ];
+ { label: 'This is Foo', value: 'foo' },
+ { label: 'This is Bar', value: 'bar' },
+ ]
- Select.vm.deselect({ label: "This is Foo", value: "foo" });
- expect(Select.vm.selectedValue).toEqual([{ label: "This is Bar", value: "bar" }]);
- });
+ Select.vm.deselect({ label: 'This is Foo', value: 'foo' })
+ expect(Select.vm.selectedValue).toEqual([
+ { label: 'This is Bar', value: 'bar' },
+ ])
+ })
- it("can deselect a pre-selected string", () => {
+ it('can deselect a pre-selected string', () => {
const Select = shallowMount(VueSelect, {
propsData: {
multiple: true,
- options: ["foo", "bar"]
- }
- });
+ options: ['foo', 'bar'],
+ },
+ })
- Select.vm.$data._value = "foo";
+ Select.vm.$data._value = 'foo'
- Select.vm.deselect("foo");
- expect(Select.vm.selectedValue).toEqual([]);
- });
+ Select.vm.deselect('foo')
+ expect(Select.vm.selectedValue).toEqual([])
+ })
- it("can deselect an option when multiple is false", () => {
- const Select = shallowMount(VueSelect);
+ it('can deselect an option when multiple is false', () => {
+ const Select = shallowMount(VueSelect)
- Select.vm.$data._value = "foo";
+ Select.vm.$data._value = 'foo'
- Select.vm.deselect("foo");
- expect(Select.vm.selectedValue).toEqual([]);
- });
+ Select.vm.deselect('foo')
+ expect(Select.vm.selectedValue).toEqual([])
+ })
- it("can determine if the value prop is empty", () => {
+ it('can determine if the value prop is empty', () => {
const Select = shallowMount(VueSelect, {
propsData: {
- options: ["one", "two", "three"]
- }
- });
+ options: ['one', 'two', 'three'],
+ },
+ })
- const select = Select.vm;
- expect(select.isValueEmpty).toEqual(true);
+ const select = Select.vm
+ expect(select.isValueEmpty).toEqual(true)
- select.select(["one"]);
- expect(select.isValueEmpty).toEqual(false);
+ select.select(['one'])
+ expect(select.isValueEmpty).toEqual(false)
- select.select("one");
- expect(select.isValueEmpty).toEqual(false);
+ select.select('one')
+ expect(select.isValueEmpty).toEqual(false)
- select.select({ label: "foo", value: "foo" });
- expect(select.isValueEmpty).toEqual(false);
+ select.select({ label: 'foo', value: 'foo' })
+ expect(select.isValueEmpty).toEqual(false)
- select.select("");
- expect(select.isValueEmpty).toEqual(true);
+ select.select('')
+ expect(select.isValueEmpty).toEqual(true)
- select.select(null);
- expect(select.isValueEmpty).toEqual(true);
- });
+ select.select(null)
+ expect(select.isValueEmpty).toEqual(true)
+ })
- it("should reset the selected values when the multiple property changes", () => {
+ it('should reset the selected values when the multiple property changes', () => {
const Select = shallowMount(VueSelect, {
propsData: {
multiple: true,
- options: ["one", "two", "three"]
- }
- });
+ options: ['one', 'two', 'three'],
+ },
+ })
- Select.setProps({ multiple: false });
- expect(Select.vm.selectedValue).toEqual([]);
+ Select.setProps({ multiple: false })
+ expect(Select.vm.selectedValue).toEqual([])
- Select.setProps({ multiple: true });
- expect(Select.vm.selectedValue).toEqual([]);
- });
+ Select.setProps({ multiple: true })
+ expect(Select.vm.selectedValue).toEqual([])
+ })
- it("can retain values present in a new array of options", () => {
+ it('can retain values present in a new array of options', () => {
const Select = shallowMount(VueSelect, {
propsData: {
- value: ["one"],
- options: ["one", "two", "three"]
- }
- });
+ value: ['one'],
+ options: ['one', 'two', 'three'],
+ },
+ })
- Select.setProps({ options: ["one", "five", "six"] });
- expect(Select.vm.selectedValue).toEqual(["one"]);
- });
+ Select.setProps({ options: ['one', 'five', 'six'] })
+ expect(Select.vm.selectedValue).toEqual(['one'])
+ })
- it("can determine if an object is already selected", () => {
+ it('can determine if an object is already selected', () => {
const Select = shallowMount(VueSelect, {
propsData: {
- value: [{ label: "one" }],
- options: [{ label: "one" }]
- }
- });
+ value: [{ label: 'one' }],
+ options: [{ label: 'one' }],
+ },
+ })
- expect(Select.vm.isOptionSelected({ label: "one" })).toEqual(true);
- });
+ expect(Select.vm.isOptionSelected({ label: 'one' })).toEqual(true)
+ })
- it("can use v-model syntax for a two way binding to a parent component", () => {
+ it('can use v-model syntax for a two way binding to a parent component', () => {
const Parent = mount({
- data: () => ({ value: "foo", options: ["foo", "bar", "baz"] }),
+ data: () => ({ value: 'foo', options: ['foo', 'bar', 'baz'] }),
template: `
`,
- components: { "v-select": VueSelect }
- });
- const Select = Parent.vm.$children[0];
+ components: { 'v-select': VueSelect },
+ })
+ const Select = Parent.vm.$children[0]
- expect(Select.value).toEqual("foo");
- expect(Select.selectedValue).toEqual(["foo"]);
+ expect(Select.value).toEqual('foo')
+ expect(Select.selectedValue).toEqual(['foo'])
- Select.select("bar");
- expect(Parent.vm.value).toEqual("bar");
- });
+ Select.select('bar')
+ expect(Parent.vm.value).toEqual('bar')
+ })
- it("can check if a string value is selected when the value is an object and multiple is true", () => {
+ it('can check if a string value is selected when the value is an object and multiple is true', () => {
const Select = shallowMount(VueSelect, {
propsData: {
multiple: true,
- value: [{ label: "foo", value: "bar" }]
- }
- });
- expect(Select.vm.isOptionSelected({ label: "foo", value: "bar" })).toEqual(true);
- });
+ value: [{ label: 'foo', value: 'bar' }],
+ },
+ })
+ expect(Select.vm.isOptionSelected({ label: 'foo', value: 'bar' })).toEqual(
+ true
+ )
+ })
it('can select two options with the same label', () => {
- const options = [{label: 'one', id: 1}, {label: 'one', id: 2}];
- const Select = mountDefault({options, multiple: true});
+ const options = [
+ { label: 'one', id: 1 },
+ { label: 'one', id: 2 },
+ ]
+ const Select = mountDefault({ options, multiple: true })
- Select.vm.select({label: 'one', id: 1});
- Select.vm.select({label: 'one', id: 2});
+ Select.vm.select({ label: 'one', id: 1 })
+ Select.vm.select({ label: 'one', id: 2 })
- expect(Select.vm.selectedValue).toEqual(options);
- });
+ expect(Select.vm.selectedValue).toEqual(options)
+ })
- describe("input Event", () => {
- it("will trigger the input event when the selection changes", () => {
- const Select = shallowMount(VueSelect);
- Select.vm.select("bar");
- expect(Select.emitted("input")[0]).toEqual(["bar"]);
- });
+ describe('input Event', () => {
+ it('will trigger the input event when the selection changes', () => {
+ const Select = shallowMount(VueSelect)
+ Select.vm.select('bar')
+ expect(Select.emitted('input')[0]).toEqual(['bar'])
+ })
- it("will trigger the input event when the selection changes and multiple is true", () => {
+ it('will trigger the input event when the selection changes and multiple is true', () => {
const Select = shallowMount(VueSelect, {
- propsData: { multiple: true, value: ["foo"], options: ["foo", "bar"] }
- });
- Select.vm.select("bar");
- expect(Select.emitted("input")[0]).toEqual([["foo", "bar"]]);
- });
+ propsData: { multiple: true, value: ['foo'], options: ['foo', 'bar'] },
+ })
+ Select.vm.select('bar')
+ expect(Select.emitted('input')[0]).toEqual([['foo', 'bar']])
+ })
- it("will not trigger the input event when multiple is true and selection is repeated", () => {
+ it('will not trigger the input event when multiple is true and selection is repeated', () => {
const Select = shallowMount(VueSelect, {
- propsData: { multiple: true, value: ["foo ", "bar"], options: ["foo", "bar", "baz"] }
- });
+ propsData: {
+ multiple: true,
+ value: ['foo ', 'bar'],
+ options: ['foo', 'bar', 'baz'],
+ },
+ })
- Select.vm.select("bar");
- expect(Select.emitted("input")).toBeFalsy();
- });
- });
+ Select.vm.select('bar')
+ expect(Select.emitted('input')).toBeFalsy()
+ })
+ })
- describe("option:selecting Event", () => {
- it("will trigger the option:selecting event when an option is selected", () => {
- const Select = shallowMount(VueSelect);
- Select.vm.select("bar");
- expect(Select.emitted("option:selecting")[0]).toEqual(["bar"]);
- });
+ describe('option:selecting Event', () => {
+ it('will trigger the option:selecting event when an option is selected', () => {
+ const Select = shallowMount(VueSelect)
+ Select.vm.select('bar')
+ expect(Select.emitted('option:selecting')[0]).toEqual(['bar'])
+ })
- it("will trigger the option:selecting event regardless of current value", () => {
+ it('will trigger the option:selecting event regardless of current value', () => {
const Select = shallowMount(VueSelect, {
- propsData: { value: ["foo"], options: ["foo", "bar"] }
- });
- Select.vm.select("foo");
- Select.vm.select("bar");
- expect(Select.emitted("option:selecting")).toEqual([["foo"], ["bar"]]);
- });
+ propsData: { value: ['foo'], options: ['foo', 'bar'] },
+ })
+ Select.vm.select('foo')
+ Select.vm.select('bar')
+ expect(Select.emitted('option:selecting')).toEqual([['foo'], ['bar']])
+ })
- it("will trigger the option:selecting event with current selected item when multiple is true", () => {
+ it('will trigger the option:selecting event with current selected item when multiple is true', () => {
const Select = shallowMount(VueSelect, {
- propsData: { multiple: true, value: ["foo"], options: ["foo", "bar"] }
- });
- Select.vm.select("bar");
- expect(Select.emitted("option:selecting")[0]).toEqual(["bar"]);
- });
+ propsData: { multiple: true, value: ['foo'], options: ['foo', 'bar'] },
+ })
+ Select.vm.select('bar')
+ expect(Select.emitted('option:selecting')[0]).toEqual(['bar'])
+ })
- it("will trigger the option:selecting event regardless of current value when multiple is true", () => {
+ it('will trigger the option:selecting event regardless of current value when multiple is true', () => {
const Select = shallowMount(VueSelect, {
- propsData: { multiple: true, value: ["foo", "bar"], options: ["foo", "bar"] }
- });
- Select.vm.select("bar");
- Select.vm.select("bar");
- expect(Select.emitted("option:selecting")).toEqual([["bar"], ["bar"]]);
- });
- });
+ propsData: {
+ multiple: true,
+ value: ['foo', 'bar'],
+ options: ['foo', 'bar'],
+ },
+ })
+ Select.vm.select('bar')
+ Select.vm.select('bar')
+ expect(Select.emitted('option:selecting')).toEqual([['bar'], ['bar']])
+ })
+ })
- describe("option:deselected Event", () => {
- it("will trigger the option:deselected event when an option is deselected", () => {
+ describe('option:deselected Event', () => {
+ it('will trigger the option:deselected event when an option is deselected', () => {
const Select = shallowMount(VueSelect, {
- propsData: { value: ["foo"], options: ["foo", "bar"] }
- });
- Select.vm.deselect("foo");
- expect(Select.emitted("option:deselected")[0]).toEqual(["foo"]);
- });
+ propsData: { value: ['foo'], options: ['foo', 'bar'] },
+ })
+ Select.vm.deselect('foo')
+ expect(Select.emitted('option:deselected')[0]).toEqual(['foo'])
+ })
- it("will trigger the option:deselected event regardless of current value", () => {
+ it('will trigger the option:deselected event regardless of current value', () => {
const Select = shallowMount(VueSelect, {
- propsData: { value: ["foo"], options: ["foo", "bar"] }
- });
- Select.vm.deselect("foo");
- Select.vm.deselect("bar");
- expect(Select.emitted("option:deselected")).toEqual([["foo"], ["bar"]]);
- });
+ propsData: { value: ['foo'], options: ['foo', 'bar'] },
+ })
+ Select.vm.deselect('foo')
+ Select.vm.deselect('bar')
+ expect(Select.emitted('option:deselected')).toEqual([['foo'], ['bar']])
+ })
- it("will trigger the option:selected event with current selected item when multiple is true", () => {
+ it('will trigger the option:selected event with current selected item when multiple is true', () => {
const Select = shallowMount(VueSelect, {
- propsData: { multiple: true, value: ["foo"], options: ["foo", "bar"] }
- });
- Select.vm.deselect("bar");
- expect(Select.emitted("option:deselected")[0]).toEqual(["bar"]);
- });
+ propsData: { multiple: true, value: ['foo'], options: ['foo', 'bar'] },
+ })
+ Select.vm.deselect('bar')
+ expect(Select.emitted('option:deselected')[0]).toEqual(['bar'])
+ })
- it("will trigger the option:selected event regardless of current value when multiple is true", () => {
+ it('will trigger the option:selected event regardless of current value when multiple is true', () => {
const Select = shallowMount(VueSelect, {
- propsData: { multiple: true, value: ["foo", "bar"], options: ["foo", "bar"] }
- });
- Select.vm.deselect("bar");
- Select.vm.deselect("bar");
- expect(Select.emitted("option:deselected")).toEqual([["bar"], ["bar"]]);
- });
- });
-});
+ propsData: {
+ multiple: true,
+ value: ['foo', 'bar'],
+ options: ['foo', 'bar'],
+ },
+ })
+ Select.vm.deselect('bar')
+ Select.vm.deselect('bar')
+ expect(Select.emitted('option:deselected')).toEqual([['bar'], ['bar']])
+ })
+ })
+})
diff --git a/tests/unit/Slots.spec.js b/tests/unit/Slots.spec.js
index 955829b..98cfcab 100644
--- a/tests/unit/Slots.spec.js
+++ b/tests/unit/Slots.spec.js
@@ -1,122 +1,153 @@
-import { mountDefault } from '../helpers';
+import { mountDefault } from '../helpers'
describe('Scoped Slots', () => {
it('receives an option object to the selected-option-container slot', () => {
const Select = mountDefault(
- {value: 'one'},
+ { value: 'one' },
{
scopedSlots: {
'selected-option-container': `{{ option.label }}`,
},
- });
+ }
+ )
- expect(Select.find({ref: 'selectedOptions'}).text()).toEqual('one');
- });
+ expect(Select.find({ ref: 'selectedOptions' }).text()).toEqual('one')
+ })
describe('Slot: selected-option', () => {
it('receives an option object to the selected-option slot', () => {
const Select = mountDefault(
- {value: 'one'},
+ { value: 'one' },
{
scopedSlots: {
'selected-option': `{{ option.label }}`,
},
- });
+ }
+ )
- expect(Select.find('.vs__selected').text()).toEqual('one');
- });
+ expect(Select.find('.vs__selected').text()).toEqual('one')
+ })
- it('opens the dropdown when clicking an option in selected-option slot',
- () => {
- const Select = mountDefault(
- {value: 'one'},
- {
- scopedSlots: {
- 'selected-option': `{{ option.label }}`,
- },
- });
-
- Select.find('.my-option').trigger('mousedown');
- expect(Select.vm.open).toEqual(true);
- });
- });
-
- it('receives an option object to the option slot in the dropdown menu',
- async () => {
+ it('opens the dropdown when clicking an option in selected-option slot', () => {
const Select = mountDefault(
- {value: 'one'},
+ { value: 'one' },
{
scopedSlots: {
- 'option': `{{ option.label }}`,
+ 'selected-option': `{{ option.label }}`,
},
- });
+ }
+ )
- Select.vm.open = true;
- await Select.vm.$nextTick();
+ Select.find('.my-option').trigger('mousedown')
+ expect(Select.vm.open).toEqual(true)
+ })
+ })
- expect(Select.find({ref: 'dropdownMenu'}).text()).toEqual('onetwothree');
- });
+ it('receives an option object to the option slot in the dropdown menu', async () => {
+ const Select = mountDefault(
+ { value: 'one' },
+ {
+ scopedSlots: {
+ option: `{{ option.label }}`,
+ },
+ }
+ )
+
+ Select.vm.open = true
+ await Select.vm.$nextTick()
+
+ expect(Select.find({ ref: 'dropdownMenu' }).text()).toEqual('onetwothree')
+ })
it('noOptions slot receives the current search text', async () => {
- const noOptions = jest.fn();
- const Select = mountDefault({}, {
- scopedSlots: {'no-options': noOptions},
- });
+ const noOptions = jest.fn()
+ const Select = mountDefault(
+ {},
+ {
+ scopedSlots: { 'no-options': noOptions },
+ }
+ )
- Select.vm.search = 'something not there';
- Select.vm.open = true;
- await Select.vm.$nextTick();
+ Select.vm.search = 'something not there'
+ Select.vm.open = true
+ await Select.vm.$nextTick()
expect(noOptions).toHaveBeenCalledWith({
loading: false,
search: 'something not there',
searching: true,
})
- });
+ })
test('header slot props', async () => {
- const header = jest.fn();
- const Select = mountDefault({}, {
- scopedSlots: {header: header},
- });
- await Select.vm.$nextTick();
+ const header = jest.fn()
+ const Select = mountDefault(
+ {},
+ {
+ scopedSlots: { header: header },
+ }
+ )
+ await Select.vm.$nextTick()
expect(Object.keys(header.mock.calls[0][0])).toEqual([
- 'search', 'loading', 'searching', 'filteredOptions', 'deselect',
- ]);
- });
+ 'search',
+ 'loading',
+ 'searching',
+ 'filteredOptions',
+ 'deselect',
+ ])
+ })
test('footer slot props', async () => {
- const footer = jest.fn();
- const Select = mountDefault({}, {
- scopedSlots: {footer: footer},
- });
- await Select.vm.$nextTick();
+ const footer = jest.fn()
+ const Select = mountDefault(
+ {},
+ {
+ scopedSlots: { footer: footer },
+ }
+ )
+ await Select.vm.$nextTick()
expect(Object.keys(footer.mock.calls[0][0])).toEqual([
- 'search', 'loading', 'searching', 'filteredOptions', 'deselect',
- ]);
- });
+ 'search',
+ 'loading',
+ 'searching',
+ 'filteredOptions',
+ 'deselect',
+ ])
+ })
test('list-header slot props', async () => {
- const header = jest.fn();
- const Select = mountDefault({}, {
- scopedSlots: {'list-header': header},
- });
- Select.vm.open = true;
- await Select.vm.$nextTick();
+ const header = jest.fn()
+ const Select = mountDefault(
+ {},
+ {
+ scopedSlots: { 'list-header': header },
+ }
+ )
+ Select.vm.open = true
+ await Select.vm.$nextTick()
expect(Object.keys(header.mock.calls[0][0])).toEqual([
- 'search', 'loading', 'searching', 'filteredOptions',
- ]);
- });
+ 'search',
+ 'loading',
+ 'searching',
+ 'filteredOptions',
+ ])
+ })
test('list-footer slot props', async () => {
- const footer = jest.fn();
- const Select = mountDefault({}, {
- scopedSlots: {'list-footer': footer},
- });
- Select.vm.open = true;
- await Select.vm.$nextTick();
+ const footer = jest.fn()
+ const Select = mountDefault(
+ {},
+ {
+ scopedSlots: { 'list-footer': footer },
+ }
+ )
+ Select.vm.open = true
+ await Select.vm.$nextTick()
expect(Object.keys(footer.mock.calls[0][0])).toEqual([
- 'search', 'loading', 'searching', 'filteredOptions',
- ]);
- });
-});
+ 'search',
+ 'loading',
+ 'searching',
+ 'filteredOptions',
+ ])
+ })
+})
diff --git a/tests/unit/Tagging.spec.js b/tests/unit/Tagging.spec.js
index c5c11dc..bc97d82 100755
--- a/tests/unit/Tagging.spec.js
+++ b/tests/unit/Tagging.spec.js
@@ -3,261 +3,258 @@ import {
searchSubmit,
selectTag,
selectWithProps,
-} from '../helpers';
-import Select from '../../src/components/Select';
+} from '../helpers'
+import Select from '../../src/components/Select'
-describe("When Tagging Is Enabled", () => {
+describe('When Tagging Is Enabled', () => {
+ it('can determine if a given option string already exists', () => {
+ const Select = selectWithProps({ taggable: true, options: ['one', 'two'] })
+ expect(Select.vm.optionExists('one')).toEqual(true)
+ expect(Select.vm.optionExists('three')).toEqual(false)
+ })
- it("can determine if a given option string already exists", () => {
- const Select = selectWithProps({ taggable: true, options: ["one", "two"] });
- expect(Select.vm.optionExists("one")).toEqual(true);
- expect(Select.vm.optionExists("three")).toEqual(false);
- });
-
- it("can determine if a given option object already exists", () => {
+ it('can determine if a given option object already exists', () => {
const Select = selectWithProps({
taggable: true,
- options: [{ label: "one" }, { label: "two" }]
- });
+ options: [{ label: 'one' }, { label: 'two' }],
+ })
- expect(Select.vm.optionExists({label: "one"})).toEqual(true);
- expect(Select.vm.optionExists({label: "three"})).toEqual(false);
- });
+ expect(Select.vm.optionExists({ label: 'one' })).toEqual(true)
+ expect(Select.vm.optionExists({ label: 'three' })).toEqual(false)
+ })
- it("can determine if a given option object already exists when using custom labels", () => {
+ it('can determine if a given option object already exists when using custom labels', () => {
const Select = selectWithProps({
taggable: true,
- options: [{ foo: "one" }, { foo: "two" }],
- label: "foo"
- });
+ options: [{ foo: 'one' }, { foo: 'two' }],
+ label: 'foo',
+ })
- const createOption = (text) => Select.vm.createOption(text);
+ const createOption = (text) => Select.vm.createOption(text)
- expect(Select.vm.optionExists(createOption("one"))).toEqual(true);
- expect(Select.vm.optionExists(createOption("three"))).toEqual(false);
- });
+ expect(Select.vm.optionExists(createOption('one'))).toEqual(true)
+ expect(Select.vm.optionExists(createOption('three'))).toEqual(false)
+ })
- it("can add the current search text as the first item in the options list", async () => {
+ it('can add the current search text as the first item in the options list', async () => {
const Select = selectWithProps({
taggable: true,
multiple: true,
- value: ["one"],
- options: ["one", "two"]
- });
+ value: ['one'],
+ options: ['one', 'two'],
+ })
- Select.vm.search = "three";
- await Select.vm.$nextTick();
- expect(Select.vm.filteredOptions).toEqual(["three"]);
- });
+ Select.vm.search = 'three'
+ await Select.vm.$nextTick()
+ expect(Select.vm.filteredOptions).toEqual(['three'])
+ })
- it("can select the current search text as a string", async () => {
+ it('can select the current search text as a string', async () => {
const Select = selectWithProps({
taggable: true,
multiple: true,
- options: ["one", "two"]
- });
+ options: ['one', 'two'],
+ })
- await selectTag(Select, "three");
+ await selectTag(Select, 'three')
- expect(Select.vm.selectedValue).toEqual(["three"]);
- });
+ expect(Select.vm.selectedValue).toEqual(['three'])
+ })
- it("can select the current search text as an object", async () => {
+ it('can select the current search text as an object', async () => {
const Select = selectWithProps({
taggable: true,
multiple: true,
- options: [{ label: "one" }]
- });
+ options: [{ label: 'one' }],
+ })
- await selectTag(Select, "two");
+ await selectTag(Select, 'two')
- expect(Select.vm.selectedValue).toEqual([
- { label: "two" }
- ]);
- });
+ expect(Select.vm.selectedValue).toEqual([{ label: 'two' }])
+ })
- it("should add a freshly created option/tag to the options list when pushTags is true", async () => {
+ it('should add a freshly created option/tag to the options list when pushTags is true', async () => {
const Select = selectWithProps({
pushTags: true,
taggable: true,
multiple: true,
- value: ["one"],
- options: ["one", "two"]
- });
+ value: ['one'],
+ options: ['one', 'two'],
+ })
- await selectTag(Select, "three");
- expect(Select.vm.pushedTags).toEqual(["three"]);
- expect(Select.vm.optionList).toEqual(["one", "two", "three"]);
- });
+ await selectTag(Select, 'three')
+ expect(Select.vm.pushedTags).toEqual(['three'])
+ expect(Select.vm.optionList).toEqual(['one', 'two', 'three'])
+ })
- it("should pushTags even if the consumer has defined a createOption callback", async () => {
+ it('should pushTags even if the consumer has defined a createOption callback', async () => {
const Select = selectWithProps({
pushTags: true,
taggable: true,
- createOption: option => option,
- options: ["one", "two"]
- });
+ createOption: (option) => option,
+ options: ['one', 'two'],
+ })
- await selectTag(Select, "three");
+ await selectTag(Select, 'three')
- expect(Select.vm.pushedTags).toEqual(["three"]);
- expect(Select.vm.optionList).toEqual(["one", "two", "three"]);
- });
+ expect(Select.vm.pushedTags).toEqual(['three'])
+ expect(Select.vm.optionList).toEqual(['one', 'two', 'three'])
+ })
- it("should add a freshly created option/tag to the options list when pushTags is true and filterable is false", async () => {
+ it('should add a freshly created option/tag to the options list when pushTags is true and filterable is false', async () => {
const Select = selectWithProps({
filterable: false,
pushTags: true,
taggable: true,
multiple: true,
- value: ["one"],
- options: ["one", "two"]
- });
+ value: ['one'],
+ options: ['one', 'two'],
+ })
- await selectTag(Select, "three");
- expect(Select.vm.pushedTags).toEqual(["three"]);
- expect(Select.vm.optionList).toEqual(["one", "two", "three"]);
- expect(Select.vm.filteredOptions).toEqual(["one", "two", "three"]);
- });
+ await selectTag(Select, 'three')
+ expect(Select.vm.pushedTags).toEqual(['three'])
+ expect(Select.vm.optionList).toEqual(['one', 'two', 'three'])
+ expect(Select.vm.filteredOptions).toEqual(['one', 'two', 'three'])
+ })
- it("wont add a freshly created option/tag to the options list when pushTags is false", async () => {
+ it('wont add a freshly created option/tag to the options list when pushTags is false', async () => {
const Select = selectWithProps({
pushTags: false,
taggable: true,
multiple: true,
- value: ["one"],
- options: ["one", "two"]
- });
+ value: ['one'],
+ options: ['one', 'two'],
+ })
- await selectTag(Select, "three");
- expect(Select.vm.optionList).toEqual(["one", "two"]);
- });
+ await selectTag(Select, 'three')
+ expect(Select.vm.optionList).toEqual(['one', 'two'])
+ })
- it("wont add a freshly created option/tag to the options list when pushTags is false and filterable is false", async () => {
+ it('wont add a freshly created option/tag to the options list when pushTags is false and filterable is false', async () => {
const Select = selectWithProps({
filterable: false,
pushTags: false,
taggable: true,
multiple: true,
- value: ["one"],
- options: ["one", "two"]
- });
+ value: ['one'],
+ options: ['one', 'two'],
+ })
- await selectTag(Select, "three");
- expect(Select.vm.optionList).toEqual(["one", "two"]);
- expect(Select.vm.filteredOptions).toEqual(["one", "two"]);
- });
+ await selectTag(Select, 'three')
+ expect(Select.vm.optionList).toEqual(['one', 'two'])
+ expect(Select.vm.filteredOptions).toEqual(['one', 'two'])
+ })
- it("should select an existing option if the search string matches a string from options", async () => {
- let two = "two";
+ it('should select an existing option if the search string matches a string from options', async () => {
+ let two = 'two'
const Select = selectWithProps({
taggable: true,
multiple: true,
- options: ["one", two]
- });
+ options: ['one', two],
+ })
- await selectTag(Select, "two");
+ await selectTag(Select, 'two')
- expect(Select.vm.selectedValue).toEqual([two]);
- });
+ expect(Select.vm.selectedValue).toEqual([two])
+ })
- it("should select an existing option if the search string matches an objects label from options", async () => {
- let two = { label: "two" };
+ it('should select an existing option if the search string matches an objects label from options', async () => {
+ let two = { label: 'two' }
const Select = selectWithProps({
taggable: true,
- options: [{ label: "one" }, two]
- });
+ options: [{ label: 'one' }, two],
+ })
- Select.vm.search = "two";
- await Select.vm.$nextTick();
+ Select.vm.search = 'two'
+ await Select.vm.$nextTick()
- searchSubmit(Select);
- expect(Select.vm.selectedValue).toEqual([two]);
- });
+ searchSubmit(Select)
+ expect(Select.vm.selectedValue).toEqual([two])
+ })
- it("should select an existing option if the search string matches an objects label from options when filter-options is false", async () => {
- let two = { label: "two" };
+ it('should select an existing option if the search string matches an objects label from options when filter-options is false', async () => {
+ let two = { label: 'two' }
const Select = selectWithProps({
taggable: true,
filterable: false,
- options: [{ label: "one" }, two]
- });
+ options: [{ label: 'one' }, two],
+ })
- Select.vm.search = "two";
- await Select.vm.$nextTick();
+ Select.vm.search = 'two'
+ await Select.vm.$nextTick()
- searchSubmit(Select);
- expect(Select.vm.selectedValue).toEqual([two]);
- });
+ searchSubmit(Select)
+ expect(Select.vm.selectedValue).toEqual([two])
+ })
- it("should not reset the selected value when the options property changes", () => {
+ it('should not reset the selected value when the options property changes', () => {
const Select = selectWithProps({
taggable: true,
multiple: true,
- value: [{ label: "one" }],
- options: [{ label: "one" }]
- });
+ value: [{ label: 'one' }],
+ options: [{ label: 'one' }],
+ })
- Select.setProps({ options: [{ label: "two" }] });
- expect(Select.vm.selectedValue).toEqual([{ label: "one" }]);
- });
+ Select.setProps({ options: [{ label: 'two' }] })
+ expect(Select.vm.selectedValue).toEqual([{ label: 'one' }])
+ })
- it("should not reset the selected value when the options property changes when filterable is false", () => {
+ it('should not reset the selected value when the options property changes when filterable is false', () => {
const Select = selectWithProps({
taggable: true,
multiple: true,
filterable: false,
- value: [{ label: "one" }],
- options: [{ label: "one" }]
- });
+ value: [{ label: 'one' }],
+ options: [{ label: 'one' }],
+ })
- Select.setProps({ options: [{ label: "two" }] });
- expect(Select.vm.selectedValue).toEqual([{ label: "one" }]);
- });
+ Select.setProps({ options: [{ label: 'two' }] })
+ expect(Select.vm.selectedValue).toEqual([{ label: 'one' }])
+ })
- it("should not allow duplicate tags when using string options", async () => {
- const Select = selectWithProps({
- taggable: true,
- multiple: true
- });
-
- await selectTag(Select, "one");
- expect(Select.vm.selectedValue).toEqual(["one"]);
- expect(Select.vm.search).toEqual("");
-
- await selectTag(Select, "one");
- expect(Select.vm.selectedValue).toEqual(["one"]);
- expect(Select.vm.search).toEqual("");
- });
-
- it("should not allow duplicate tags when using object options", async () => {
+ it('should not allow duplicate tags when using string options', async () => {
const Select = selectWithProps({
taggable: true,
multiple: true,
- options: [{ label: "two" }]
- });
- const spy = jest.spyOn(Select.vm, 'select');
+ })
- await selectTag(Select, "one");
- expect(Select.vm.selectedValue).toEqual([{ label: "one" }]);
- expect(spy).lastCalledWith({label: 'one'});
- expect(Select.vm.search).toEqual("");
+ await selectTag(Select, 'one')
+ expect(Select.vm.selectedValue).toEqual(['one'])
+ expect(Select.vm.search).toEqual('')
- await selectTag(Select, "one");
- expect(Select.vm.selectedValue).toEqual([{ label: "one" }]);
- expect(Select.vm.search).toEqual("");
- });
+ await selectTag(Select, 'one')
+ expect(Select.vm.selectedValue).toEqual(['one'])
+ expect(Select.vm.search).toEqual('')
+ })
- it("will select an existing option on tab", async () => {
+ it('should not allow duplicate tags when using object options', async () => {
+ const Select = selectWithProps({
+ taggable: true,
+ multiple: true,
+ options: [{ label: 'two' }],
+ })
+ const spy = jest.spyOn(Select.vm, 'select')
+
+ await selectTag(Select, 'one')
+ expect(Select.vm.selectedValue).toEqual([{ label: 'one' }])
+ expect(spy).lastCalledWith({ label: 'one' })
+ expect(Select.vm.search).toEqual('')
+
+ await selectTag(Select, 'one')
+ expect(Select.vm.selectedValue).toEqual([{ label: 'one' }])
+ expect(Select.vm.search).toEqual('')
+ })
+
+ it('will select an existing option on tab', async () => {
const Select = mountDefault({
taggable: true,
- selectOnTab: true
- });
+ selectOnTab: true,
+ })
- Select.vm.typeAheadPointer = 0;
- Select.find({ ref: "search" }).trigger("keydown.tab");
+ Select.vm.typeAheadPointer = 0
+ Select.find({ ref: 'search' }).trigger('keydown.tab')
- await Select.vm.$nextTick();
- expect(Select.vm.selectedValue).toEqual(['one']);
+ await Select.vm.$nextTick()
+ expect(Select.vm.selectedValue).toEqual(['one'])
})
-});
+})
diff --git a/tests/unit/TypeAhead.spec.js b/tests/unit/TypeAhead.spec.js
index f2f8119..ca4adcc 100755
--- a/tests/unit/TypeAhead.spec.js
+++ b/tests/unit/TypeAhead.spec.js
@@ -1,47 +1,47 @@
-import { shallowMount } from "@vue/test-utils";
-import VueSelect from "../../src/components/Select";
-import { mountDefault, mountWithoutTestUtils } from "../helpers";
-import typeAheadMixin from "../../src/mixins/typeAheadPointer";
-import Vue from "vue";
+import { shallowMount } from '@vue/test-utils'
+import VueSelect from '../../src/components/Select'
+import { mountDefault, mountWithoutTestUtils } from '../helpers'
+import typeAheadMixin from '../../src/mixins/typeAheadPointer'
+import Vue from 'vue'
-describe("Moving the Typeahead Pointer", () => {
- it("should set the pointer to zero when the filteredOptions watcher is called", async () => {
+describe('Moving the Typeahead Pointer', () => {
+ it('should set the pointer to zero when the filteredOptions watcher is called', async () => {
const Select = shallowMount(VueSelect, {
- propsData: { options: ["one", "two", "three"] },
- sync: false
- });
+ propsData: { options: ['one', 'two', 'three'] },
+ sync: false,
+ })
- Select.vm.search = "one";
+ Select.vm.search = 'one'
- await Select.vm.$nextTick();
- expect(Select.vm.typeAheadPointer).toEqual(0);
- });
+ await Select.vm.$nextTick()
+ expect(Select.vm.typeAheadPointer).toEqual(0)
+ })
- it("should move the pointer visually up the list on up arrow keyUp", () => {
- const Select = mountDefault();
+ it('should move the pointer visually up the list on up arrow keyUp', () => {
+ const Select = mountDefault()
- Select.vm.typeAheadPointer = 1;
+ Select.vm.typeAheadPointer = 1
- Select.find({ ref: "search" }).trigger("keydown.up");
+ Select.find({ ref: 'search' }).trigger('keydown.up')
- expect(Select.vm.typeAheadPointer).toEqual(0);
- });
+ expect(Select.vm.typeAheadPointer).toEqual(0)
+ })
- it("should move the pointer visually down the list on down arrow keyUp", () => {
- const Select = mountDefault();
+ it('should move the pointer visually down the list on down arrow keyUp', () => {
+ const Select = mountDefault()
- Select.vm.typeAheadPointer = 1;
+ Select.vm.typeAheadPointer = 1
- Select.find({ ref: "search" }).trigger("keydown.down");
+ Select.find({ ref: 'search' }).trigger('keydown.down')
- expect(Select.vm.typeAheadPointer).toEqual(2);
- });
+ expect(Select.vm.typeAheadPointer).toEqual(2)
+ })
- it("should not move the pointer past the end of the list", () => {
- const Select = mountDefault();
+ it('should not move the pointer past the end of the list', () => {
+ const Select = mountDefault()
- Select.vm.typeAheadPointer = 2;
- Select.vm.typeAheadDown();
- expect(Select.vm.typeAheadPointer).toEqual(2);
- });
-});
+ Select.vm.typeAheadPointer = 2
+ Select.vm.typeAheadDown()
+ expect(Select.vm.typeAheadPointer).toEqual(2)
+ })
+})
diff --git a/tests/unit/utility/sortAndStringify.spec.js b/tests/unit/utility/sortAndStringify.spec.js
index 414e2a0..dbf649a 100644
--- a/tests/unit/utility/sortAndStringify.spec.js
+++ b/tests/unit/utility/sortAndStringify.spec.js
@@ -1,14 +1,15 @@
-import sortAndStringify from '../../../src/utility/sortAndStringify';
+import sortAndStringify from '../../../src/utility/sortAndStringify'
test('it will stringify an object', () => {
- expect(sortAndStringify({hello: 'world'})).toEqual('{"hello":"world"}');
-});
+ expect(sortAndStringify({ hello: 'world' })).toEqual('{"hello":"world"}')
+})
test('it will sort attributes alphabetically', () => {
- expect(sortAndStringify({b: 'b', a: 'a'})).toEqual('{"a":"a","b":"b"}');
-});
+ expect(sortAndStringify({ b: 'b', a: 'a' })).toEqual('{"a":"a","b":"b"}')
+})
test('comparing two objects with unsorted keys', () => {
- expect(sortAndStringify({b: 'b', a: 'a'}))
- .toEqual(sortAndStringify({a: 'a', b: 'b'}))
-});
+ expect(sortAndStringify({ b: 'b', a: 'a' })).toEqual(
+ sortAndStringify({ a: 'a', b: 'b' })
+ )
+})
diff --git a/tests/unit/utility/uniqueId.spec.js b/tests/unit/utility/uniqueId.spec.js
index c425a7c..2febb51 100644
--- a/tests/unit/utility/uniqueId.spec.js
+++ b/tests/unit/utility/uniqueId.spec.js
@@ -1,5 +1,5 @@
-import uniqueId from '../../../src/utility/uniqueId';
+import uniqueId from '../../../src/utility/uniqueId'
test('it generates a unique number', () => {
- expect(uniqueId()).not.toEqual(uniqueId());
-});
+ expect(uniqueId()).not.toEqual(uniqueId())
+})