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

@quilted/preact-testing

Package Overview
Dependencies
Maintainers
1
Versions
27
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@quilted/preact-testing - npm Package Compare versions

Comparing version 0.1.0 to 0.1.1

46

build/typescript/matchers.d.ts

@@ -1,32 +0,28 @@

import type { ComponentType, Context as ReactContext } from 'preact';
import type { ComponentType, Context } from 'preact';
import type { PropsFor } from './types.ts';
import { toContainReactHTML, toHaveReactDataProps } from './matchers/dom.ts';
import { toHaveReactProps } from './matchers/props.ts';
import { toContainReactComponent, toContainReactComponentTimes } from './matchers/components.ts';
import { toContainReactText } from './matchers/text.ts';
import { toProvideReactContext } from './matchers/context.ts';
import { toContainPreactHTML, toHavePreactDataProps } from './matchers/dom.ts';
import { toHavePreactProps } from './matchers/props.ts';
import { toContainPreactComponent, toContainPreactComponentTimes } from './matchers/components.ts';
import { toContainPreactText } from './matchers/text.ts';
import { toProvidePreactContext } from './matchers/context.ts';
export interface CustomMatchers<R = unknown> {
toHaveReactProps(props: Record<string, unknown>): void;
toContainReactComponent<Type extends string | ComponentType<any>>(type: Type, props?: Partial<PropsFor<Type>>): R;
toContainReactComponentTimes<Type extends string | ComponentType<any>>(type: Type, times: number, props?: Partial<PropsFor<Type>>): R;
toProvideReactContext<Type>(context: ReactContext<Type>, value?: Type): R;
toContainReactText(text: string): R;
}
export declare const matchers: {
toHaveReactProps: typeof toHaveReactProps;
toContainReactComponent: typeof toContainReactComponent;
toContainReactComponentTimes: typeof toContainReactComponentTimes;
toProvideReactContext: typeof toProvideReactContext;
toContainReactText: typeof toContainReactText;
};
export interface CustomDOMMatchers<R = unknown> {
toContainReactHTML(text: string): R;
toHaveReactDataProps(data: {
toHavePreactProps(props: Record<string, unknown>): void;
toContainPreactComponent<Type extends string | ComponentType<any>>(type: Type, props?: Partial<PropsFor<Type>>): R;
toContainPreactComponentTimes<Type extends string | ComponentType<any>>(type: Type, times: number, props?: Partial<PropsFor<Type>>): R;
toProvidePreactContext<Type>(context: Context<Type>, value?: Type): R;
toContainPreactText(text: string): R;
toContainPreactHTML(text: string): R;
toHavePreactDataProps(data: {
[key: string]: string;
}): R;
}
export declare const domMatchers: {
toContainReactHTML: typeof toContainReactHTML;
toHaveReactDataProps: typeof toHaveReactDataProps;
export declare const matchers: {
toHavePreactProps: typeof toHavePreactProps;
toContainPreactComponent: typeof toContainPreactComponent;
toContainPreactComponentTimes: typeof toContainPreactComponentTimes;
toProvidePreactContext: typeof toProvidePreactContext;
toContainPreactText: typeof toContainPreactText;
toContainPreactHTML: typeof toContainPreactHTML;
toHavePreactDataProps: typeof toHavePreactDataProps;
};
//# sourceMappingURL=matchers.d.ts.map
import type { ComponentType } from 'preact';
import type { MatcherState } from 'expect';
import type { MatcherState, MatcherUtils } from 'expect';
import { Node, PropsFor } from '../types.ts';
export declare function toContainReactComponent<Type extends string | ComponentType<any>>(this: MatcherState, node: Node<any>, type: Type, props?: Partial<PropsFor<Type>>): {
export declare function toContainPreactComponent<Type extends string | ComponentType<any>>(this: MatcherState & MatcherUtils, node: Node<any>, type: Type, props?: Partial<PropsFor<Type>>): {
pass: boolean;
message: () => string;
};
export declare function toContainReactComponentTimes<Type extends string | ComponentType<any>>(this: MatcherState, node: Node<unknown>, type: Type, times: number, props?: Partial<PropsFor<Type>>): {
export declare function toContainPreactComponentTimes<Type extends string | ComponentType<any>>(this: MatcherState & MatcherUtils, node: Node<unknown>, type: Type, times: number, props?: Partial<PropsFor<Type>>): {
pass: boolean;

@@ -10,0 +10,0 @@ message: () => string;

import { Context } from 'preact';
import type { MatcherState } from 'expect';
import type { Node } from '../types.ts';
export declare function toProvideReactContext<Type>(this: MatcherState, node: Node<any>, Context: Context<Type>, value?: Type): {
export declare function toProvidePreactContext<Type>(this: MatcherState, node: Node<any>, Context: Context<Type>, value?: Type): {
pass: boolean;

@@ -6,0 +6,0 @@ message: () => string;

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

import type { MatcherState } from 'expect';
import type { MatcherState, MatcherUtils } from 'expect';
import type { Node } from '../types.ts';
export declare function toContainReactHTML<Props>(this: MatcherState, node: Node<Props>, text: string): {
export declare function toContainPreactHTML<Props>(this: MatcherState, node: Node<Props>, text: string): {
pass: boolean;
message: () => string;
};
export declare function toHaveReactDataProps(this: MatcherState, node: Node<unknown>, data: {
export declare function toHavePreactDataProps(this: MatcherState & MatcherUtils, node: Node<unknown>, data: {
[key: string]: string;

@@ -9,0 +9,0 @@ }): {

@@ -1,4 +0,4 @@

import type { MatcherState } from 'expect';
import type { MatcherState, MatcherUtils } from 'expect';
import type { Node } from '../types.ts';
export declare function toHaveReactProps<Props>(this: MatcherState, node: Node<Props>, props: Partial<Props>): {
export declare function toHavePreactProps<Props>(this: MatcherState & MatcherUtils, node: Node<Props>, props: Partial<Props>): {
pass: boolean;

@@ -5,0 +5,0 @@ message: () => string;

import type { MatcherState } from 'expect';
import type { Node } from '../types.ts';
export declare function toContainReactText<Props>(this: MatcherState, node: Node<Props>, text: string): {
export declare function toContainPreactText<Props>(this: MatcherState, node: Node<Props>, text: string): {
pass: boolean;

@@ -5,0 +5,0 @@ message: () => string;

@@ -16,4 +16,5 @@ import type { ComponentType } from 'preact';

}): string | null;
export declare function getObjectSubset(object: any, subset: any): any;
export declare function pluralize(word: string, count: number): string;
export declare function printReceivedWithHighlight(text: string, start: number, length: number): string;
//# sourceMappingURL=utilities.d.ts.map
# @quilted/react-testing
## 0.1.1
### Patch Changes
- [`4bf3e6ad`](https://github.com/lemonmade/quilt/commit/4bf3e6ade2922fe5de175b07fdaf21bb679895bf) Thanks [@lemonmade](https://github.com/lemonmade)! - Fix custom matcher equality testing
- [`4df2d665`](https://github.com/lemonmade/quilt/commit/4df2d665ae22201afa86e7a5f214f73f5428ea4e) Thanks [@lemonmade](https://github.com/lemonmade)! - Fix React testing exports
## 0.5.32

@@ -4,0 +12,0 @@

{
"name": "@quilted/preact-testing",
"type": "module",
"version": "0.1.0",
"version": "0.1.1",
"repository": {

@@ -6,0 +6,0 @@ "type": "git",

@@ -1,13 +0,13 @@

import type {ComponentType, Context as ReactContext} from 'preact';
import type {ComponentType, Context} from 'preact';
import type {PropsFor} from './types.ts';
import {toContainReactHTML, toHaveReactDataProps} from './matchers/dom.ts';
import {toHaveReactProps} from './matchers/props.ts';
import {toContainPreactHTML, toHavePreactDataProps} from './matchers/dom.ts';
import {toHavePreactProps} from './matchers/props.ts';
import {
toContainReactComponent,
toContainReactComponentTimes,
toContainPreactComponent,
toContainPreactComponentTimes,
} from './matchers/components.ts';
import {toContainReactText} from './matchers/text.ts';
import {toProvideReactContext} from './matchers/context.ts';
import {toContainPreactText} from './matchers/text.ts';
import {toProvidePreactContext} from './matchers/context.ts';

@@ -17,8 +17,8 @@ // @see https://vitest.dev/guide/extending-matchers.html

export interface CustomMatchers<R = unknown> {
toHaveReactProps(props: Record<string, unknown>): void;
toContainReactComponent<Type extends string | ComponentType<any>>(
toHavePreactProps(props: Record<string, unknown>): void;
toContainPreactComponent<Type extends string | ComponentType<any>>(
type: Type,
props?: Partial<PropsFor<Type>>,
): R;
toContainReactComponentTimes<Type extends string | ComponentType<any>>(
toContainPreactComponentTimes<Type extends string | ComponentType<any>>(
type: Type,

@@ -28,22 +28,16 @@ times: number,

): R;
toProvideReactContext<Type>(context: ReactContext<Type>, value?: Type): R;
toContainReactText(text: string): R;
toProvidePreactContext<Type>(context: Context<Type>, value?: Type): R;
toContainPreactText(text: string): R;
toContainPreactHTML(text: string): R;
toHavePreactDataProps(data: {[key: string]: string}): R;
}
export const matchers = {
toHaveReactProps,
toContainReactComponent,
toContainReactComponentTimes,
toProvideReactContext,
toContainReactText,
toHavePreactProps,
toContainPreactComponent,
toContainPreactComponentTimes,
toProvidePreactContext,
toContainPreactText,
toContainPreactHTML,
toHavePreactDataProps,
};
export interface CustomDOMMatchers<R = unknown> {
toContainReactHTML(text: string): R;
toHaveReactDataProps(data: {[key: string]: string}): R;
}
export const domMatchers = {
toContainReactHTML,
toHaveReactDataProps,
};
import type {ComponentType} from 'preact';
import type {MatcherState} from 'expect';
import type {MatcherState, MatcherUtils} from 'expect';
import {

@@ -18,8 +18,9 @@ matcherHint,

printType,
getObjectSubset,
} from './utilities.ts';
export function toContainReactComponent<
export function toContainPreactComponent<
Type extends string | ComponentType<any>,
>(
this: MatcherState,
this: MatcherState & MatcherUtils,
node: Node<any>,

@@ -30,3 +31,3 @@ type: Type,

assertIsNode(node, {
expectation: 'toContainReactComponent',
expectation: 'toContainPreactComponent',
isNot: this.isNot,

@@ -36,3 +37,3 @@ });

assertIsType(type, {
expectation: 'toContainReactComponent',
expectation: 'toContainPreactComponent',
isNot: this.isNot,

@@ -46,5 +47,3 @@ });

: foundByType.filter((element) =>
Object.keys(props).every((key) =>
Object.is((props as any)[key], (element.props as any)[key]),
),
this.equals(props, getObjectSubset(element.props, props)),
);

@@ -56,4 +55,4 @@

? () =>
`${matcherHint('.not.toContainReactComponent')}\n\n` +
`Expected the React element:\n ${receivedColor(node.toString())}\n` +
`${matcherHint('.not.toContainPreactComponent')}\n\n` +
`Expected the Preact element:\n ${receivedColor(node.toString())}\n` +
`Not to contain component:\n ${expectedColor(printType(type))}\n${

@@ -67,4 +66,6 @@ props ? `With props matching:\n ${printExpected(props)}\n` : ''

`${
`${matcherHint('.toContainReactComponent')}\n\n` +
`Expected the React element:\n ${receivedColor(node.toString())}\n` +
`${matcherHint('.toContainPreactComponent')}\n\n` +
`Expected the Preact element:\n ${receivedColor(
node.toString(),
)}\n` +
`To contain component:\n ${expectedColor(printType(type))}\n${

@@ -90,6 +91,6 @@ props ? `With props matching:\n ${printExpected(props)}\n` : ''

export function toContainReactComponentTimes<
export function toContainPreactComponentTimes<
Type extends string | ComponentType<any>,
>(
this: MatcherState,
this: MatcherState & MatcherUtils,
node: Node<unknown>,

@@ -101,3 +102,3 @@ type: Type,

assertIsNode(node, {
expectation: 'toContainReactComponentTimes',
expectation: 'toContainPreactComponentTimes',
isNot: this.isNot,

@@ -107,3 +108,3 @@ });

assertIsType(type, {
expectation: 'toContainReactComponent',
expectation: 'toContainPreactComponent',
isNot: this.isNot,

@@ -117,5 +118,3 @@ });

: foundByType.filter((element) =>
Object.keys(props).every((key) =>
Object.is((props as any)[key], (element.props as any)[key]),
),
this.equals(props, getObjectSubset(element.props, props)),
);

@@ -128,4 +127,4 @@

[
`${matcherHint('.not.toContainReactComponentTimes')}\n`,
`Expected the React element:\n ${receivedColor(node.toString())}`,
`${matcherHint('.not.toContainPreactComponentTimes')}\n`,
`Expected the Preact element:\n ${receivedColor(node.toString())}`,
`Not to contain component:\n ${expectedColor(printType(type))}`,

@@ -136,4 +135,4 @@ `${times} ${pluralize('time', times)}, but it did.`,

[
`${matcherHint('.toContainReactComponentTimes')}\n`,
`Expected the React element:\n ${receivedColor(node.toString())}`,
`${matcherHint('.toContainPreactComponentTimes')}\n`,
`Expected the Preact element:\n ${receivedColor(node.toString())}`,
`To contain component:\n ${expectedColor(printType(type))}`,

@@ -140,0 +139,0 @@ `${times} ${pluralize('time', times)}, but it was found ${

@@ -14,3 +14,3 @@ import {Context} from 'preact';

export function toProvideReactContext<Type>(
export function toProvidePreactContext<Type>(
this: MatcherState,

@@ -22,3 +22,3 @@ node: Node<any>,

assertIsNode(node, {
expectation: 'toProvideReactContext',
expectation: 'toProvidePreactContext',
isNot: this.isNot,

@@ -39,4 +39,4 @@ });

? () =>
`${matcherHint('.not.toProvideReactContext')}\n\n` +
`Expected the React element:\n ${receivedColor(node.toString())}\n` +
`${matcherHint('.not.toProvidePreactContext')}\n\n` +
`Expected the Preact element:\n ${receivedColor(node.toString())}\n` +
`Not to contain context provider:\n ${expectedColor(

@@ -52,4 +52,6 @@ printType(Context.Provider),

`${
`${matcherHint('.toProvideReactContext')}\n\n` +
`Expected the React element:\n ${receivedColor(node.toString())}\n` +
`${matcherHint('.toProvidePreactContext')}\n\n` +
`Expected the Preact element:\n ${receivedColor(
node.toString(),
)}\n` +
`To contain context provider:\n ${expectedColor(

@@ -56,0 +58,0 @@ printType(Context.Provider),

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

import type {MatcherState} from 'expect';
import type {MatcherState, MatcherUtils} from 'expect';
import {

@@ -11,6 +11,6 @@ matcherHint,

import {toHaveReactProps} from './props.ts';
import {toHavePreactProps} from './props.ts';
import {assertIsNode, printReceivedWithHighlight} from './utilities.ts';
export function toContainReactHTML<Props>(
export function toContainPreactHTML<Props>(
this: MatcherState,

@@ -21,3 +21,3 @@ node: Node<Props>,

assertIsNode(node, {
expectation: 'toContainReactHTML',
expectation: 'toContainPreactHTML',
isNot: this.isNot,

@@ -32,4 +32,4 @@ });

? () =>
`${matcherHint('.not.toContainReactHTML', node.toString())}\n\n` +
`Expected the React element:\n ${receivedColor(node.toString())}\n` +
`${matcherHint('.not.toContainPreactHTML', node.toString())}\n\n` +
`Expected the Preact element:\n ${receivedColor(node.toString())}\n` +
`Not to contain HTML:\n ${printExpected(text)}\n` +

@@ -42,4 +42,4 @@ `But it did:\n ${printReceivedWithHighlight(

: () =>
`${matcherHint('.not.toContainReactHTML', node.toString())}\n\n` +
`Expected the React element:\n ${receivedColor(node.toString())}\n` +
`${matcherHint('.not.toContainPreactHTML', node.toString())}\n\n` +
`Expected the Preact element:\n ${receivedColor(node.toString())}\n` +
`With HTML content:\n ${printReceived(nodeHTML)}\n` +

@@ -51,8 +51,8 @@ `To contain HTML:\n ${printExpected(text)}\n`;

export function toHaveReactDataProps(
this: MatcherState,
export function toHavePreactDataProps(
this: MatcherState & MatcherUtils,
node: Node<unknown>,
data: {[key: string]: string},
) {
return toHaveReactProps.call(this, node, data);
return toHavePreactProps.call(this, node, data);
}

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

import type {MatcherState} from 'expect';
import type {MatcherState, MatcherUtils} from 'expect';
import {

@@ -11,6 +11,6 @@ matcherHint,

import {assertIsNode, diffPropsForNode} from './utilities.ts';
import {assertIsNode, diffPropsForNode, getObjectSubset} from './utilities.ts';
export function toHaveReactProps<Props>(
this: MatcherState,
export function toHavePreactProps<Props>(
this: MatcherState & MatcherUtils,
node: Node<Props>,

@@ -20,3 +20,3 @@ props: Partial<Props>,

assertIsNode(node, {
expectation: 'toHaveReactProps',
expectation: 'toHavePreactProps',
isNot: this.isNot,

@@ -35,10 +35,8 @@ });

const pass = Object.keys(props).every((key) =>
Object.is((props as any)[key], (node.props as any)[key]),
);
const pass = this.equals(props, getObjectSubset(node.props, props));
const message = pass
? () =>
`${matcherHint('.not.toHaveReactProps', node.toString())}\n\n` +
`Expected the React element:\n ${receivedColor(node.toString())}\n` +
`${matcherHint('.not.toHavePreactProps', node.toString())}\n\n` +
`Expected the Preact element:\n ${receivedColor(node.toString())}\n` +
`Not to have props:\n ${printExpected(props)}\n` +

@@ -52,4 +50,6 @@ `Received:\n ${printReceived(node.props)}\n`

return (
`${matcherHint('.toHaveReactProps', node.toString())}\n\n` +
`Expected the React element:\n ${receivedColor(node.toString())}\n` +
`${matcherHint('.toHavePreactProps', node.toString())}\n\n` +
`Expected the Preact element:\n ${receivedColor(
node.toString(),
)}\n` +
`To have props:\n ${printExpected(props)}\n` +

@@ -56,0 +56,0 @@ `Received:\n ${printReceived(node.props)}\n${

@@ -13,3 +13,3 @@ import type {MatcherState} from 'expect';

export function toContainReactText<Props>(
export function toContainPreactText<Props>(
this: MatcherState,

@@ -20,3 +20,3 @@ node: Node<Props>,

assertIsNode(node, {
expectation: 'toContainReactText',
expectation: 'toContainPreactText',
isNot: this.isNot,

@@ -31,4 +31,4 @@ });

? () =>
`${matcherHint('.not.toContainReactText', node.toString())}\n\n` +
`Expected the React element:\n ${receivedColor(node.toString())}\n` +
`${matcherHint('.not.toContainPreactText', node.toString())}\n\n` +
`Expected the Preact element:\n ${receivedColor(node.toString())}\n` +
`Not to contain text:\n ${printExpected(text)}\n` +

@@ -41,4 +41,4 @@ `But it did:\n ${printReceivedWithHighlight(

: () =>
`${matcherHint('.not.toContainReactText', node.toString())}\n\n` +
`Expected the React element:\n ${receivedColor(node.toString())}\n` +
`${matcherHint('.not.toContainPreactText', node.toString())}\n\n` +
`Expected the Preact element:\n ${receivedColor(node.toString())}\n` +
`With text content:\n ${printReceived(nodeText)}\n` +

@@ -45,0 +45,0 @@ `To contain string:\n ${printExpected(text)}\n`;

@@ -26,3 +26,3 @@ import type {ComponentType} from 'preact';

'received',
)} value must be an @shopify/react-testing Root or Element object`,
)} value must be an @quilted/preact-testing Root or Element object`,
`Received ${receivedColor(

@@ -41,3 +41,3 @@ 'null',

'received',
)} value must be an @shopify/react-testing Root or Element object`,
)} value must be an @quilted/preact-testing Root or Element object`,
`Received an ${receivedColor(

@@ -56,3 +56,3 @@ 'array of Root or Element objects',

'received',
)} value must be an @shopify/react-testing Root or Element object`,
)} value must be an @quilted/preact-testing Root or Element object`,
printWithType('Received', node, printReceived),

@@ -136,3 +136,3 @@ ),

// Original from https://github.com/facebook/jest/blob/master/packages/expect/source/utils.ts#L107
function getObjectSubset(object: any, subset: any): any {
export function getObjectSubset(object: any, subset: any): any {
if (Array.isArray(object)) {

@@ -139,0 +139,0 @@ if (Array.isArray(subset) && subset.length === object.length) {

{
"extends": "@quilted/typescript/project.json",
"extends": "@quilted/craft/typescript/project.json",
"compilerOptions": {

@@ -4,0 +4,0 @@ "rootDir": "source",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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