/dom-snap

Stop making useless DOM snapshots

Primary LanguageTypeScriptMIT LicenseMIT

dom-snap

Stop making useless DOM snapshots. Instead describe your elements (and props) that you are intrested in and make text-based snapshot of them.

  1. Describe elements
import { domSnap, element, setDefaultComponents } from 'dom-snap'

const Button = element({
  name: 'button',
  selector: 'button',
  props: {
    disabled: node => node.disabled,
    label: node => `[${node.textContent || node.id}]`,
  },
  flags: props => ({
    r: props.disabled,
  }),
})

setDefaultComponents([Button])

// for this dom
// <div>
//     <button>Foo</button>
//     <button id="bar" disabled/>
// </div>
const { getSnap } = domSnap()
expect(getSnap()).toBe(`
[ ] [Foo]
[r] [bar]
`)

TSDX Bootstrap

This project was bootstrapped with TSDX.

Local Development

Below is a list of commands you will probably find useful.

npm start or yarn start

Runs the project in development/watch mode. Your project will be rebuilt upon changes. TSDX has a special logger for you convenience. Error messages are pretty printed and formatted for compatibility VS Code's Problems tab.

Your library will be rebuilt if you make edits.

npm run build or yarn build

Bundles the package to the dist folder. The package is optimized and bundled with Rollup into multiple formats (CommonJS, UMD, and ES Module).

npm test or yarn test

Runs the test watcher (Jest) in an interactive mode. By default, runs tests related to files changed since the last commit.