# teaspoon **Repository Path**: mirrors_jquense/teaspoon ## Basic Information - **Project Name**: teaspoon - **Description**: A jQuery like API for testing React elements and rendered components. - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2020-08-09 - **Last Updated**: 2026-02-28 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README teaspoon ======== # Project deprecated!! teaspoon will not be updated to support React v16+. As of the recent release of [enzyme](http://airbnb.io/enzyme/) v3, the differences between it and teaspoon have shrunk to almost complete API parity (baring a few things), Given that enzyme is more widely used and maintained it makes sense to switch to that going forward rather than continute to maintain teaspoon and it's underlying pieces. Thanks for using teaspoon ya'll! Just the right amount of abstraction for writing clear, and concise React component tests. **Table of Contents** *generated with [DocToc](https://github.com/thlorenz/doctoc)* - [Getting Started](#getting-started) - [Usage](#usage) - [Using selectors](#using-selectors) - [Complex selectors](#complex-selectors) - [Testing patterns](#testing-patterns) - [Using `tap()`](#using-tap) - [Test specific querying ("ref" style querying).](#test-specific-querying-ref-style-querying) - [Build warnings with webpack](#build-warnings-with-webpack) - [Adding collection methods and pseudo selectors](#adding-collection-methods-and-pseudo-selectors) - [createPseudo(pseudo: string, handler: (innerValue: string) => (node: Node) => bool)](#createpseudopseudo-string-handler-innervalue-string--node-node--bool) - [API](#api) - [Rendering](#rendering) - [`$.fn.render([Bool renderIntoDocument, HTMLElement mountPoint, Object context ])`](#fnrenderbool-renderintodocument-htmlelement-mountpoint-object-context-) - [`$.fn.shallowRender([props, context]) -> ElementCollection`](#fnshallowrenderprops-context---elementcollection) - [`$.element.fn.update()`](#elementfnupdate) - [`$.instance.fn.unmount()`](#instancefnunmount) - [Utility methods and properties](#utility-methods-and-properties) - [`$.selector` => selector _(alias: $.s)_](#selector--selector-_alias-s_) - [`$.dom(instance) => HTMLElement`](#dominstance--htmlelement) - [`$.compileSelector(selector) => (node) => bool`](#compileselectorselector--node--bool) - [`$.defaultContext(context: ?object) => (node) => bool`](#defaultcontextcontext-object--node--bool) - [`$.fn.length`](#fnlength) - [`$.fn.unwrap() => Element|Instance|HTMLElement`](#fnunwrap--elementinstancehtmlelement) - [`$.fn.get() => Array` (alias: toArray())](#fnget--array-alias-toarray) - [`$.fn.tap() => function(Collection)`](#fntap--functioncollection) - [`$.fn.end() => Collection`](#fnend--collection) - [`$.fn.each(Function iteratorFn)`](#fneachfunction-iteratorfn) - [`$.fn.map(Function iteratorFn)`](#fnmapfunction-iteratorfn) - [`$.fn.reduce(Function iteratorFn, [initialValue]) -> Collection`](#fnreducefunction-iteratorfn-initialvalue---collection) - [`$.fn.reduceRight(Function iteratorFn) -> Collection`](#fnreducerightfunction-iteratorfn---collection) - [`$.fn.some(Function iteratorFn) -> bool`](#fnsomefunction-iteratorfn---bool) - [`$.fn.every(Function iteratorFn) -> bool`](#fneveryfunction-iteratorfn---bool) - [`$.instance.fn.dom -> HTMLElement`](#instancefndom---htmlelement) - [Accessors](#accessors) - [`$.fn.props`](#fnprops) - [`$.fn.state`](#fnstate) - [`$.fn.context`](#fncontext) - [Traversal methods](#traversal-methods) - [`$.fn.find(selector)`](#fnfindselector) - [`$.fn.filter(selector)`](#fnfilterselector) - [`$.fn.is(selector) -> Bool`](#fnisselector---bool) - [`$.fn.children([selector])`](#fnchildrenselector) - [`$.fn.parent([selector])`](#fnparentselector) - [`$.fn.parents([selector])`](#fnparentsselector) - [`$.fn.closest([selector])`](#fnclosestselector) - [`$.fn.first([selector])`](#fnfirstselector) - [`$.fn.last([selector])`](#fnlastselector) - [`$.fn.only()`](#fnonly) - [`$.fn.single(selector)`](#fnsingleselector) - [`$.fn.any([selector])`](#fnanyselector) - [`$.fn.none([selector])`](#fnnoneselector) - [`$.fn.text()`](#fntext) - [Events](#events) - [`$.instance.fn.trigger(String eventName, [Object data])`](#instancefntriggerstring-eventname-object-data) - [`$.element.fn.trigger(String eventName, [Object data])`](#elementfntriggerstring-eventname-object-data) ## Getting Started To get started install teaspoon via npm: ```sh npm i --save-dev teaspoon ``` Teaspoon is test environment agnostic, so you can (and should) bring your own test runner and frameworks. If you plan on doing normal component rendering (not just shallow rendering) you will also need a DOM environment, whether that's a browser, headless browser, or jsdom. Like jQuery teaspoon exports a function that creates a collection of nodes; except in this case you select React elements instead of DOM nodes. ### Usage ```js import $ from 'teaspoon'; let $div = $(
); $div.length // 1 $div[0] // ReactElement{ type: 'div', props: {} ... } ``` Since there is no globally accessible "document" of React elements like there is of DOM nodes, you need to start by selecting a tree. Once you have a tree you can query it with css selectors and jQuery-like methods. ```js let elements = (