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

@quilted/react-testing

Package Overview
Dependencies
Maintainers
1
Versions
161
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@quilted/react-testing - npm Package Compare versions

Comparing version 0.5.32 to 0.6.0

build/esm/matchers.mjs

1

build/typescript/implementations/react-dom.d.ts

@@ -6,2 +6,3 @@ import { isNode } from '../environment.tsx';

export type { Node, NodeApi, Root, RootApi, HTMLNodeExtensions, CustomRender, CustomRenderResult, CustomRenderOptions, CustomRenderExtendOptions, HookRunner, Environment, EnvironmentOptions, ContextOption, RenderOption, ActionsOption, };
export declare const environment: Environment<HTMLNodeExtensions>;
declare const render: CustomRender<import("../types.ts").EmptyObject, import("../types.ts").EmptyObject, import("../types.ts").EmptyObject, HTMLNodeExtensions, false>, createRender: <RenderOptions extends import("../types.ts").PlainObject = import("../types.ts").EmptyObject, Context_1 extends import("../types.ts").PlainObject = import("../types.ts").EmptyObject, Actions extends import("../types.ts").PlainObject = import("../types.ts").EmptyObject, Async extends boolean = false>(options: CustomRenderOptions<RenderOptions, Context_1, Context_1, Actions, Actions, HTMLNodeExtensions, Async>) => CustomRender<RenderOptions, Context_1, Actions, HTMLNodeExtensions, Async>, rendered: Set<Root<any, any, any, HTMLNodeExtensions>>, destroyAll: () => void;

@@ -8,0 +9,0 @@ export { render, createRender, rendered, destroyAll };

import type { CustomRender, CustomRenderResult, CustomRenderOptions, CustomRenderExtendOptions, HookRunner, Environment, EnvironmentOptions, ContextOption, RenderOption, ActionsOption } from '../environment.tsx';
export type { CustomRender, CustomRenderResult, CustomRenderOptions, CustomRenderExtendOptions, HookRunner, Environment, EnvironmentOptions, ContextOption, RenderOption, ActionsOption, };
export declare const environment: Environment<import("../types.ts").EmptyObject>;
declare const render: CustomRender<import("../types.ts").EmptyObject, import("../types.ts").EmptyObject, import("../types.ts").EmptyObject, import("../types.ts").EmptyObject, false>, createRender: <RenderOptions extends import("../types.ts").PlainObject = import("../types.ts").EmptyObject, Context_1 extends import("../types.ts").PlainObject = import("../types.ts").EmptyObject, Actions extends import("../types.ts").PlainObject = import("../types.ts").EmptyObject, Async extends boolean = false>(options: CustomRenderOptions<RenderOptions, Context_1, Context_1, Actions, Actions, import("../types.ts").EmptyObject, Async>) => CustomRender<RenderOptions, Context_1, Actions, import("../types.ts").EmptyObject, Async>, rendered: Set<import("../types.ts").Root<any, any, any, import("../types.ts").EmptyObject>>, destroyAll: () => void;
export { render, createRender, rendered, destroyAll };
//# sourceMappingURL=test-renderer.d.ts.map

10

build/typescript/matchers/dom.d.ts
import type { MatcherState } from 'expect';
import type { Node, HTMLNodeExtensions } from '../types.ts';
declare global {
namespace jest {
interface Matchers<R, T = {}> {
toContainReactHTML(text: string): void;
toHaveReactDataProps(data: {
[key: string]: string;
}): void;
}
}
}
export declare function toContainReactHTML<Props>(this: MatcherState, node: Node<Props, HTMLNodeExtensions>, text: string): {

@@ -14,0 +4,0 @@ pass: boolean;

@@ -5,7 +5,7 @@ import type { ComponentType } from 'react';

expectation: string;
isNot: boolean;
isNot?: boolean;
}): void;
export declare function assertIsType(type: unknown, { expectation, isNot }: {
expectation: string;
isNot: boolean;
isNot?: boolean;
}): void;

@@ -12,0 +12,0 @@ export declare function diffs(element: Node<any, any>[], props: Record<string, any>, expand?: boolean): string;

@@ -53,3 +53,3 @@ import type { ComponentType, ComponentPropsWithoutRef, HTMLAttributes, Context } from 'react';

export interface HTMLNodeExtensions {
readonly isDom: boolean;
readonly isDOM: boolean;
readonly domNodes: HTMLElement[];

@@ -56,0 +56,0 @@ readonly domNode: HTMLElement | null;

# @quilted/react-testing
## 0.6.0
### Minor Changes
- [#645](https://github.com/lemonmade/quilt/pull/645) [`302ed847`](https://github.com/lemonmade/quilt/commit/302ed8479f9c035ef39d48137de958dba50690ca) Thanks [@lemonmade](https://github.com/lemonmade)! - Removed CommonJS support
The `require` export condition is no longer provided by any package. Quilt only supports ESModules, so if you need to use the CommonJS version, you will need to pre-process Quilt’s output code on your own.
## 0.5.32

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

{
"name": "@quilted/react-testing",
"type": "module",
"version": "0.5.32",
"version": "0.6.0",
"repository": {

@@ -20,4 +20,3 @@ "type": "git",

"quilt:esnext": "./build/esnext/index.esnext",
"import": "./build/esm/index.mjs",
"require": "./build/cjs/index.cjs"
"import": "./build/esm/index.mjs"
},

@@ -28,25 +27,21 @@ "./dom": {

"quilt:esnext": "./build/esnext/implementations/react-dom.esnext",
"import": "./build/esm/implementations/react-dom.mjs",
"require": "./build/cjs/implementations/react-dom.cjs"
"import": "./build/esm/implementations/react-dom.mjs"
},
"./dom-matchers": {
"types": "./build/typescript/matchers/dom.d.ts",
"quilt:source": "./source/matchers/dom.ts",
"quilt:esnext": "./build/esnext/matchers/dom.esnext",
"import": "./build/esm/matchers/dom.mjs",
"require": "./build/cjs/matchers/dom.cjs"
"./environment": {
"types": "./build/typescript/environment.d.ts",
"quilt:source": "./source/environment.tsx",
"quilt:esnext": "./build/esnext/environment.esnext",
"import": "./build/esm/environment.mjs"
},
"./matchers": {
"types": "./build/typescript/matchers/index.d.ts",
"quilt:source": "./source/matchers/index.ts",
"quilt:esnext": "./build/esnext/matchers/index.esnext",
"import": "./build/esm/matchers/index.mjs",
"require": "./build/cjs/matchers/index.cjs"
"types": "./build/typescript/matchers.d.ts",
"quilt:source": "./source/matchers.ts",
"quilt:esnext": "./build/esnext/matchers.esnext",
"import": "./build/esm/matchers.mjs"
},
"./preact": {
"types": "./build/typescript/implementations/preact.d.ts",
"quilt:source": "./source/implementations/preact.ts",
"quilt:esnext": "./build/esnext/implementations/preact.esnext",
"import": "./build/esm/implementations/preact.mjs",
"require": "./build/cjs/implementations/preact.cjs"
"types": "./build/typescript/implementations/react-dom.d.ts",
"quilt:source": "./source/preact.ts",
"quilt:esnext": "./build/esnext/preact.esnext",
"import": "./build/esm/preact.mjs"
}

@@ -60,3 +55,3 @@ },

],
"dom-matchers": [
"environment": [
"./build/typescript/matchers/dom.d.ts"

@@ -66,8 +61,2 @@ ],

"./build/typescript/matchers/index.d.ts"
],
"preact": [
"./build/typescript/implementations/preact.d.ts"
],
"environment": [
"./build/typescript/environment.d.ts"
]

@@ -78,2 +67,3 @@ }

"dependencies": {
"@quilted/preact-testing": "^0.1.0",
"jest-matcher-utils": "^27.0.0"

@@ -83,4 +73,3 @@ },

"@types/react-test-renderer": "^18.0.0",
"@jest/globals": "^27.0.0",
"expect": "^27.0.0",
"expect": "^29.0.0",
"preact": "^10.17.0",

@@ -92,3 +81,2 @@ "react": "^18.2.0",

"peerDependencies": {
"@jest/globals": "^27.0.0",
"preact": "^10.17.0",

@@ -100,5 +88,2 @@ "react": "^18.0.0",

"peerDependenciesMeta": {
"@jest/globals": {
"optional": true
},
"preact": {

@@ -122,3 +107,6 @@ "optional": true

]
},
"scripts": {
"build": "rollup --config configuration/rollup.config.js"
}
}

@@ -12,3 +12,2 @@ # `@quilted/react-testing`

- [DOM](#dom)
- [Preact](#preact)
- [Test structure](#test-structure)

@@ -76,33 +75,2 @@ - [Matchers](#matchers)

### Preact
This library also provides a `@quilted/react-testing/preact` entrypoint that can be used in Preact projects. It provides the same API (including the DOM additions) as `@quilted/react-testing/dom`, but uses all of Preact’s rendering and test utilities for the test environment.
```tsx
import h from 'preact';
import {render} from '@quilted/react-testing/preact';
function PayNowButton({onPay}) {
return <button onClick={onPay}>Pay</button>;
}
const payNowButton = render(<PayNowButton onPay={pay} />);
const expectedContent = payNowButton.html.includes('<button>Pay</button>');
```
If your application prefers to reference `react` and alias it to `preact/compat` at build or test time, you can do the same in your tests by importing from `@quilted/react-testing` and aliasing the import to `@quilted/react-testing/preact`. The following configuration shows how you’d accomplish this using [Jest’s `moduleNameMapper` option](https://jestjs.io/docs/en/configuration#modulenamemapper-objectstring-string--arraystring):
```js
// jest.config.js
module.exports = {
// Rest of config...
moduleNameMapper: {
'^react$': 'preact/compat',
'^@quilted/react-testing$': '@quilted/react-testing/preact',
'^@quilted/react-testing/dom$': '@quilted/react-testing/preact',
},
};
```
### Test Structure

@@ -109,0 +77,0 @@

@@ -55,6 +55,3 @@ import {createRoot, type Root as ReactDomRoot} from 'react-dom/client';

const {render, createRender, rendered, destroyAll} = createEnvironment<
Context,
HTMLNodeExtensions
>({
export const environment = createEnvironment<Context, HTMLNodeExtensions>({
act,

@@ -79,2 +76,4 @@ mount(tree) {

const {render, createRender, rendered, destroyAll} = environment;
export {render, createRender, rendered, destroyAll};

@@ -97,3 +96,3 @@

const instance = fiber.stateNode;
const isDom = typeof fiber.type === 'string';
const isDOM = typeof fiber.type === 'string';

@@ -118,4 +117,4 @@ function children() {

instance: fiber.stateNode,
get isDom() {
return isDom;
get isDOM() {
return isDOM;
},

@@ -166,3 +165,3 @@ get domNodes() {

function getDomNodes(node: NodeApi<any, HTMLNodeExtensions>) {
if (isDom) return [instance];
if (isDOM) return [instance];

@@ -172,3 +171,3 @@ return node.children

(child): child is Node<unknown, HTMLNodeExtensions> =>
typeof child !== 'string' && child.isDom,
typeof child !== 'string' && child.isDOM,
)

@@ -175,0 +174,0 @@ .map((child) => child.instance);

@@ -39,18 +39,18 @@ import {

const {render, createRender, rendered, destroyAll} = createEnvironment<Context>(
{
act,
mount(tree) {
const renderer = createTestRenderer(tree);
return {renderer};
},
unmount({renderer}) {
renderer.unmount();
},
update(_, create, {renderer}) {
return createNodeFromTestInstance(renderer.root, create) as any;
},
export const environment = createEnvironment<Context>({
act,
mount(tree) {
const renderer = createTestRenderer(tree);
return {renderer};
},
);
unmount({renderer}) {
renderer.unmount();
},
update(_, create, {renderer}) {
return createNodeFromTestInstance(renderer.root, create) as any;
},
});
const {render, createRender, rendered, destroyAll} = environment;
type Create = Parameters<EnvironmentOptions<any>['update']>[1];

@@ -57,0 +57,0 @@

@@ -44,3 +44,3 @@ import type {ComponentType} from 'react';

Object.keys(props).every((key) =>
this.equals((props as any)[key], (element.props as any)[key]),
Object.is((props as any)[key], (element.props as any)[key]),
),

@@ -110,3 +110,3 @@ );

Object.keys(props).every((key) =>
this.equals((props as any)[key], (element.props as any)[key]),
Object.is((props as any)[key], (element.props as any)[key]),
),

@@ -113,0 +113,0 @@ );

@@ -30,3 +30,3 @@ import {Context} from 'react';

: foundByType.filter((element) =>
this.equals(value, element.prop('value')),
Object.is(value, element.prop('value')),
);

@@ -33,0 +33,0 @@

@@ -9,4 +9,2 @@ import type {MatcherState} from 'expect';

import {expect} from '@jest/globals';
import type {Node, HTMLNodeExtensions} from '../types.ts';

@@ -17,18 +15,2 @@

declare global {
// As far as I know, this is needed for the module augmentation to work.
// eslint-disable-next-line @typescript-eslint/no-namespace
namespace jest {
interface Matchers<R, T = {}> {
toContainReactHTML(text: string): void;
toHaveReactDataProps(data: {[key: string]: string}): void;
}
}
}
expect.extend({
toContainReactHTML,
toHaveReactDataProps,
});
export function toContainReactHTML<Props>(

@@ -35,0 +17,0 @@ this: MatcherState,

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

const pass = Object.keys(props).every((key) =>
this.equals((props as any)[key], (node.props as any)[key]),
Object.is((props as any)[key], (node.props as any)[key]),
);

@@ -37,0 +37,0 @@

@@ -18,3 +18,3 @@ import type {ComponentType} from 'react';

node: unknown,
{expectation, isNot}: {expectation: string; isNot: boolean},
{expectation, isNot = false}: {expectation: string; isNot?: boolean},
) {

@@ -64,3 +64,3 @@ if (node == null) {

type: unknown,
{expectation, isNot}: {expectation: string; isNot: boolean},
{expectation, isNot = false}: {expectation: string; isNot?: boolean},
) {

@@ -67,0 +67,0 @@ if (type == null) {

@@ -134,3 +134,3 @@ import type {

export interface HTMLNodeExtensions {
readonly isDom: boolean;
readonly isDOM: boolean;
readonly domNodes: HTMLElement[];

@@ -137,0 +137,0 @@ readonly domNode: HTMLElement | null;

@@ -8,4 +8,3 @@ {

"include": ["source"],
"exclude": ["quilt.project.ts", "**/*.test.ts", "**/*.test.tsx"],
"references": []
"references": [{"path": "../preact-testing"}]
}

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