Skip to content

josephwynn-sc/jest-preset-preact

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

31 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

jest-preset-preact

Jest preset containing all required configuration for writing tests for preact.

Features:

  • Transpiles JSX to h()
  • Aliases for react imports to point to preact/compat
  • Automatically serialize Preact VNodes in snapshots
  • Stub style imports (.css, .less, .sass/scss, etc)
  • Add typeahead preview for filtering in jest's watch mode

Usage

Install it via npm or yarn:

npm install --save-dev jest-preset-preact
# or via yarn
yarn add -D jest-preset-preact

...and add the preset to your jest.config.js file.

// jest.config.js
module.exports = {
	preset: 'jest-preset-preact',
};

You can override the default Babel config by providing your own Babel config file:

// babel.config.js
module.exports = {
  env: {
    test: {
      plugins: [
        [
          "@babel/plugin-transform-react-jsx",
          {
            runtime: "automatic",
            importSource: "preact"
          }
        ]
      ]
    }
  }
}

This, for example, would enable the runtime JSX transform instead of the classic.

License

MIT, see the LICENSE file.

About

Jest preset for testing Preact apps

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 94.7%
  • TypeScript 4.8%
  • Less 0.5%