Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

vue-test-utils-compat

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

vue-test-utils-compat - npm Package Compare versions

Comparing version 0.0.10 to 0.0.11

src/compats/wrapper-props.js

7

CHANGELOG.md

@@ -0,1 +1,8 @@

# 0.0.11
- Expose all array methods on WrapperArray
- Added flags:
- EXPORT_ERROR_WRAPPER
- WRAPPER_UNWRAP_PROPS
# 0.0.8

@@ -2,0 +9,0 @@

112

dist/vue-test-utils-compat.cjs.js
'use strict';
function install$2(VTU, compatConfig) {
function install$3(VTU, compatConfig) {
[VTU.config.plugins.DOMWrapper, VTU.config.plugins.VueWrapper].forEach((pluginHost) =>

@@ -39,26 +39,47 @@ pluginHost.install((wrapper) => {

function wrapResults(results) {
return {
...results,
wrappers: results,
at(i) {
return results[i];
},
function install$2(VTU, compatConfig) {
VTU.config.plugins.VueWrapper.install((wrapper) => {
const { props } = wrapper;
return {
props(prop) {
const originalProps = props.call(wrapper, prop);
if (!compatConfig.WRAPPER_UNWRAP_PROPS) {
return originalProps;
}
filter(condition) {
return wrapResults(results.filter(condition));
},
if (prop === undefined) {
return new Proxy(originalProps, {
get(target, key) {
const value = target[key];
// eslint-disable-next-line no-underscore-dangle
return value?.__v_raw ?? value;
},
});
}
trigger(...params) {
results.forEach((w) => w.trigger(...params));
},
// eslint-disable-next-line no-underscore-dangle
return originalProps?.__v_raw ?? originalProps;
},
};
});
}
exists() {
return results.length > 0 && results.every((x) => x.exists());
},
class WrapperArray extends Array {
constructor(results) {
super();
Object.assign(this, results);
this.wrappers = results;
}
get length() {
return results.length;
},
};
at(i) {
return this[i];
}
trigger(...params) {
this.wrappers.forEach((w) => w.trigger(...params));
}
exists() {
return this.length > 0 && this.wrappers.every((x) => x.exists());
}
}

@@ -84,7 +105,7 @@

return config.WRAPPER_FIND_ALL ? wrapResults(results) : results;
return config.WRAPPER_FIND_ALL ? new WrapperArray(results) : results;
},
findAllComponents: (...args) => {
const results = findAllComponents.call(wrapper, ...args);
return config.WRAPPER_FIND_ALL ? wrapResults(results) : results;
return config.WRAPPER_FIND_ALL ? new WrapperArray(results) : results;
},

@@ -370,2 +391,4 @@ };

EXPORT_CREATE_WRAPPER: "EXPORT_CREATE_WRAPPER",
EXPORT_ERROR_WRAPPER: "EXPORT_ERROR_WRAPPER",
EXPORT_WRAPPER_ARRAY: "EXPORT_WRAPPER_ARRAY",

@@ -390,2 +413,3 @@ GLOBAL_STUBS: "GLOBAL_STUBS",

WRAPPER_ATTRIBUTES_VALUE: "WRAPPER_ATTRIBUTES_VALUE",
WRAPPER_UNWRAP_PROPS: "WRAPPER_UNWRAP_PROPS",
WRAPPER_DESTROY: "WRAPPER_DESTROY",

@@ -443,5 +467,9 @@ WRAPPER_DO_NOT_INCLUDE_NATIVE_EVENTS_IN_EMITTED: "WRAPPER_DO_NOT_INCLUDE_NATIVE_EVENTS_IN_EMITTED",

VTU.createWrapper = (vm) => (vm instanceof HTMLElement ? new VTU.DOMWrapper(vm) : new VTU.VueWrapper(null, vm));
// eslint-disable-next-line no-param-reassign
VTU.Wrapper = VTU.BaseWrapper;
if (VTU.default) {
// eslint-disable-next-line no-param-reassign
VTU.default.createWrapper = VTU.createWrapper;
// eslint-disable-next-line no-param-reassign
VTU.default.Wrapper = VTU.Wrapper;
}

@@ -459,2 +487,36 @@ }

if (compatConfig.EXPORT_ERROR_WRAPPER) {
// eslint-disable-next-line no-param-reassign
VTU.ErrorWrapper = function ErrorWrapper(wrapperType) {
return new Proxy(this, {
get(obj, prop) {
switch (prop) {
case "then":
// allows for better errors when wrapping `find` in `await`
// https://github.com/vuejs/test-utils/issues/638
return undefined;
case "exists":
return () => false;
default:
throw new Error(`Cannot call ${String(prop)} on an empty ${wrapperType}.`);
}
},
});
};
if (VTU.default) {
// eslint-disable-next-line no-param-reassign
VTU.default.ErrorWrapper = VTU.ErrorWrapper;
}
}
if (compatConfig.EXPORT_WRAPPER_ARRAY) {
// eslint-disable-next-line no-param-reassign
VTU.WrapperArray = WrapperArray;
if (VTU.default) {
// eslint-disable-next-line no-param-reassign
VTU.default.WrapperArray = VTU.WrapperArray;
}
}
if (compatConfig.WRAPPER_DESTROY) {

@@ -538,2 +600,6 @@ VTU.config.plugins.VueWrapper.install((wrapper) => ({

if (compatConfig.WRAPPER_ATTRIBUTES_VALUE || compatConfig.WRAPPER_ATTRIBUTES_DISABLED) {
install$3(VTU, compatConfig);
}
if (compatConfig.WRAPPER_UNWRAP_PROPS) {
install$2(VTU, compatConfig);

@@ -540,0 +606,0 @@ }

@@ -1,2 +0,2 @@

function install$2(VTU, compatConfig) {
function install$3(VTU, compatConfig) {
[VTU.config.plugins.DOMWrapper, VTU.config.plugins.VueWrapper].forEach((pluginHost) =>

@@ -37,26 +37,47 @@ pluginHost.install((wrapper) => {

function wrapResults(results) {
return {
...results,
wrappers: results,
at(i) {
return results[i];
},
function install$2(VTU, compatConfig) {
VTU.config.plugins.VueWrapper.install((wrapper) => {
const { props } = wrapper;
return {
props(prop) {
const originalProps = props.call(wrapper, prop);
if (!compatConfig.WRAPPER_UNWRAP_PROPS) {
return originalProps;
}
filter(condition) {
return wrapResults(results.filter(condition));
},
if (prop === undefined) {
return new Proxy(originalProps, {
get(target, key) {
const value = target[key];
// eslint-disable-next-line no-underscore-dangle
return value?.__v_raw ?? value;
},
});
}
trigger(...params) {
results.forEach((w) => w.trigger(...params));
},
// eslint-disable-next-line no-underscore-dangle
return originalProps?.__v_raw ?? originalProps;
},
};
});
}
exists() {
return results.length > 0 && results.every((x) => x.exists());
},
class WrapperArray extends Array {
constructor(results) {
super();
Object.assign(this, results);
this.wrappers = results;
}
get length() {
return results.length;
},
};
at(i) {
return this[i];
}
trigger(...params) {
this.wrappers.forEach((w) => w.trigger(...params));
}
exists() {
return this.length > 0 && this.wrappers.every((x) => x.exists());
}
}

@@ -82,7 +103,7 @@

return config.WRAPPER_FIND_ALL ? wrapResults(results) : results;
return config.WRAPPER_FIND_ALL ? new WrapperArray(results) : results;
},
findAllComponents: (...args) => {
const results = findAllComponents.call(wrapper, ...args);
return config.WRAPPER_FIND_ALL ? wrapResults(results) : results;
return config.WRAPPER_FIND_ALL ? new WrapperArray(results) : results;
},

@@ -368,2 +389,4 @@ };

EXPORT_CREATE_WRAPPER: "EXPORT_CREATE_WRAPPER",
EXPORT_ERROR_WRAPPER: "EXPORT_ERROR_WRAPPER",
EXPORT_WRAPPER_ARRAY: "EXPORT_WRAPPER_ARRAY",

@@ -388,2 +411,3 @@ GLOBAL_STUBS: "GLOBAL_STUBS",

WRAPPER_ATTRIBUTES_VALUE: "WRAPPER_ATTRIBUTES_VALUE",
WRAPPER_UNWRAP_PROPS: "WRAPPER_UNWRAP_PROPS",
WRAPPER_DESTROY: "WRAPPER_DESTROY",

@@ -441,5 +465,9 @@ WRAPPER_DO_NOT_INCLUDE_NATIVE_EVENTS_IN_EMITTED: "WRAPPER_DO_NOT_INCLUDE_NATIVE_EVENTS_IN_EMITTED",

VTU.createWrapper = (vm) => (vm instanceof HTMLElement ? new VTU.DOMWrapper(vm) : new VTU.VueWrapper(null, vm));
// eslint-disable-next-line no-param-reassign
VTU.Wrapper = VTU.BaseWrapper;
if (VTU.default) {
// eslint-disable-next-line no-param-reassign
VTU.default.createWrapper = VTU.createWrapper;
// eslint-disable-next-line no-param-reassign
VTU.default.Wrapper = VTU.Wrapper;
}

@@ -457,2 +485,36 @@ }

if (compatConfig.EXPORT_ERROR_WRAPPER) {
// eslint-disable-next-line no-param-reassign
VTU.ErrorWrapper = function ErrorWrapper(wrapperType) {
return new Proxy(this, {
get(obj, prop) {
switch (prop) {
case "then":
// allows for better errors when wrapping `find` in `await`
// https://github.com/vuejs/test-utils/issues/638
return undefined;
case "exists":
return () => false;
default:
throw new Error(`Cannot call ${String(prop)} on an empty ${wrapperType}.`);
}
},
});
};
if (VTU.default) {
// eslint-disable-next-line no-param-reassign
VTU.default.ErrorWrapper = VTU.ErrorWrapper;
}
}
if (compatConfig.EXPORT_WRAPPER_ARRAY) {
// eslint-disable-next-line no-param-reassign
VTU.WrapperArray = WrapperArray;
if (VTU.default) {
// eslint-disable-next-line no-param-reassign
VTU.default.WrapperArray = VTU.WrapperArray;
}
}
if (compatConfig.WRAPPER_DESTROY) {

@@ -536,2 +598,6 @@ VTU.config.plugins.VueWrapper.install((wrapper) => ({

if (compatConfig.WRAPPER_ATTRIBUTES_VALUE || compatConfig.WRAPPER_ATTRIBUTES_DISABLED) {
install$3(VTU, compatConfig);
}
if (compatConfig.WRAPPER_UNWRAP_PROPS) {
install$2(VTU, compatConfig);

@@ -538,0 +604,0 @@ }

{
"name": "vue-test-utils-compat",
"version": "0.0.10",
"version": "0.0.11",
"description": "Compat layer for @vue/test-utils@2.x",

@@ -5,0 +5,0 @@ "main": "dist/vue-test-utils-compat.cjs.js",

@@ -176,2 +176,8 @@ # vue-test-utils-compat [![npm badge](https://img.shields.io/npm/v/vue-test-utils-compat)](https://npmjs.com/vue-test-utils-compat)

### EXPORT_ERROR_WRAPPER (added in v0.0.11)
Adds `ErrorWrapper` class to `@vue/test-utils` module
➡️ Migration strategy: replace `new ErrorWrapper()` calls to `createWrapperError`
### MOUNT_ARGS_COMPONENTS (added in v0.0.3)

@@ -263,2 +269,8 @@

### WRAPPER_UNWRAP_PROPS (added in v0.0.11)
Unwraps props from `reactive()` container to allow strict checks like `.toBe` pass
➡️ Migration strategy: when asserting props of the component use relaxed check (like `.toStrictEqual`) instead strict `===` equality
### WRAPPER_DESTROY

@@ -265,0 +277,0 @@

@@ -1,25 +0,19 @@

function wrapResults(results) {
return {
...results,
wrappers: results,
at(i) {
return results[i];
},
export class WrapperArray extends Array {
constructor(results) {
super();
Object.assign(this, results);
this.wrappers = results;
}
filter(condition) {
return wrapResults(results.filter(condition));
},
at(i) {
return this[i];
}
trigger(...params) {
results.forEach((w) => w.trigger(...params));
},
trigger(...params) {
this.wrappers.forEach((w) => w.trigger(...params));
}
exists() {
return results.length > 0 && results.every((x) => x.exists());
},
get length() {
return results.length;
},
};
exists() {
return this.length > 0 && this.wrappers.every((x) => x.exists());
}
}

@@ -45,7 +39,7 @@

return config.WRAPPER_FIND_ALL ? wrapResults(results) : results;
return config.WRAPPER_FIND_ALL ? new WrapperArray(results) : results;
},
findAllComponents: (...args) => {
const results = findAllComponents.call(wrapper, ...args);
return config.WRAPPER_FIND_ALL ? wrapResults(results) : results;
return config.WRAPPER_FIND_ALL ? new WrapperArray(results) : results;
},

@@ -52,0 +46,0 @@ };

import { install as installWrapperAttributesCompat } from "./compats/wrapper-attributes.js";
import { install as installWrapperFindAllCompat } from "./compats/wrapper-find-all.js";
import { install as installWrapperPropsCompat } from "./compats/wrapper-props.js";
import { install as installWrapperFindAllCompat, WrapperArray } from "./compats/wrapper-find-all.js";
import { install as installWrapperFindCompat } from "./compats/wrapper-find.js";

@@ -18,2 +19,4 @@ import { createLocalVue } from "./utils/create-local-vue.js";

EXPORT_CREATE_WRAPPER: "EXPORT_CREATE_WRAPPER",
EXPORT_ERROR_WRAPPER: "EXPORT_ERROR_WRAPPER",
EXPORT_WRAPPER_ARRAY: "EXPORT_WRAPPER_ARRAY",

@@ -38,2 +41,3 @@ GLOBAL_STUBS: "GLOBAL_STUBS",

WRAPPER_ATTRIBUTES_VALUE: "WRAPPER_ATTRIBUTES_VALUE",
WRAPPER_UNWRAP_PROPS: "WRAPPER_UNWRAP_PROPS",
WRAPPER_DESTROY: "WRAPPER_DESTROY",

@@ -91,5 +95,9 @@ WRAPPER_DO_NOT_INCLUDE_NATIVE_EVENTS_IN_EMITTED: "WRAPPER_DO_NOT_INCLUDE_NATIVE_EVENTS_IN_EMITTED",

VTU.createWrapper = (vm) => (vm instanceof HTMLElement ? new VTU.DOMWrapper(vm) : new VTU.VueWrapper(null, vm));
// eslint-disable-next-line no-param-reassign
VTU.Wrapper = VTU.BaseWrapper;
if (VTU.default) {
// eslint-disable-next-line no-param-reassign
VTU.default.createWrapper = VTU.createWrapper;
// eslint-disable-next-line no-param-reassign
VTU.default.Wrapper = VTU.Wrapper;
}

@@ -107,2 +115,36 @@ }

if (compatConfig.EXPORT_ERROR_WRAPPER) {
// eslint-disable-next-line no-param-reassign
VTU.ErrorWrapper = function ErrorWrapper(wrapperType) {
return new Proxy(this, {
get(obj, prop) {
switch (prop) {
case "then":
// allows for better errors when wrapping `find` in `await`
// https://github.com/vuejs/test-utils/issues/638
return undefined;
case "exists":
return () => false;
default:
throw new Error(`Cannot call ${String(prop)} on an empty ${wrapperType}.`);
}
},
});
};
if (VTU.default) {
// eslint-disable-next-line no-param-reassign
VTU.default.ErrorWrapper = VTU.ErrorWrapper;
}
}
if (compatConfig.EXPORT_WRAPPER_ARRAY) {
// eslint-disable-next-line no-param-reassign
VTU.WrapperArray = WrapperArray;
if (VTU.default) {
// eslint-disable-next-line no-param-reassign
VTU.default.WrapperArray = VTU.WrapperArray;
}
}
if (compatConfig.WRAPPER_DESTROY) {

@@ -189,2 +231,6 @@ VTU.config.plugins.VueWrapper.install((wrapper) => ({

if (compatConfig.WRAPPER_UNWRAP_PROPS) {
installWrapperPropsCompat(VTU, compatConfig);
}
if (compatConfig.WRAPPER_VUE_SET_VALUE_USES_DOM) {

@@ -191,0 +237,0 @@ VTU.config.plugins.VueWrapper.install((wrapper) => ({

@@ -53,3 +53,3 @@ import { jest, describe, afterEach, beforeEach, it, expect } from "@jest/globals";

it.only("components option is ignored and is overwriting original", async () => {
it("components option is ignored and is overwriting original", async () => {
// VTU overrides "unknown" options, so components will be overwritten, not rendering a child

@@ -56,0 +56,0 @@ expect(wrapper.text()).toBe("i-am-root");

@@ -35,3 +35,3 @@ import { jest, describe, afterEach, beforeEach, it, expect } from "@jest/globals";

it.only("should return correct value from attributes call", async () => {
it("should return correct value from attributes call", async () => {
expect(wrapper.find("input").attributes().value).toBe("correct");

@@ -38,0 +38,0 @@ expect(wrapper.find("input").attributes("value")).toBe("correct");

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc