@ficusjs/testing
Advanced tools
| { | ||
| "reject": ["standard"] | ||
| } |
| import { html, renderer } from '@ficusjs/renderers/htm-preact' | ||
| import { createCustomElement } from '@ficusjs/core/custom-element' | ||
| createCustomElement('basic-comp', { | ||
| renderer, | ||
| render () { | ||
| return html`<p>Basic component</p>` | ||
| } | ||
| }) |
| import test from 'ava' | ||
| import { init, render } from '../src/index.mjs' | ||
| test.before(init) | ||
| test('render basic component', async t => { | ||
| const comp = await render('basic-comp', () => import('./component.mjs')) | ||
| t.is(comp.querySelector('p').textContent, 'Basic component') | ||
| }) |
+5
-0
@@ -7,2 +7,7 @@ # Changelog | ||
| ## [2.1.0] - 2022-10-21 | ||
| ### Added | ||
| - Add ability to pass options to JSDOM in the `init` function | ||
| ## [2.0.0] - 2022-10-03 | ||
@@ -9,0 +14,0 @@ |
+6
-2
| { | ||
| "name": "@ficusjs/testing", | ||
| "version": "2.0.0", | ||
| "version": "2.1.0", | ||
| "description": "Helper functions for component testing", | ||
@@ -11,3 +11,4 @@ "type": "module", | ||
| "scripts": { | ||
| "lint": "standard \"src/**/*.js\"" | ||
| "lint": "standard \"src/**/*.mjs\"", | ||
| "test": "ava \"test/**/*.spec.mjs\"" | ||
| }, | ||
@@ -34,2 +35,5 @@ "repository": { | ||
| "devDependencies": { | ||
| "@ficusjs/core": "2.0.0", | ||
| "@ficusjs/renderers": "5.3.0", | ||
| "ava": "4.3.3", | ||
| "standard": "16.0.4" | ||
@@ -36,0 +40,0 @@ }, |
+12
-3
@@ -33,4 +33,13 @@ # FicusJS testing | ||
| test.before(init) | ||
| // if passing options to JSDOM | ||
| test.before(() => init({ runScripts: 'dangerously' })) | ||
| ``` | ||
| The `init` function accepts the following optional arguments: | ||
| | Name | Type | Description | | ||
| |------------|----------|---------------------------------------| | ||
| | `options` | `object` | An object of options to pass to JSDOM | | ||
| ### render function | ||
@@ -56,5 +65,5 @@ | ||
| | Name | Type | Description | | ||
| | --- | --- | --- | | ||
| | `tagName` | `string` | The web component tag name | | ||
| | Name | Type | Description | | ||
| |------------|------------|------------------------------------------------------------------------| | ||
| | `tagName` | `string` | The web component tag name | | ||
| | `importer` | `function` | A function that registers a web component. This can return a `Promise` | | ||
@@ -61,0 +70,0 @@ |
+2
-2
| import { JSDOM } from 'jsdom' | ||
| export function init () { | ||
| const dom = new JSDOM('<!DOCTYPE html><html><head></head><body></body></html>') | ||
| export function init (options = {}) { | ||
| const dom = new JSDOM('<!DOCTYPE html><html><head></head><body></body></html>', options) | ||
| globalThis.dom = dom | ||
@@ -6,0 +6,0 @@ globalThis.Node = dom.Node |
18524
7.79%14
27.27%36
89.47%98
10.11%4
300%