Nodeschool Public Materials
Share your code. npm Orgs help your team discover, share, and reuse code. Create a free org »

marko-tester

9.1.0 • Public • Published

Build Status Test Coverage

marko-tester

A utility that helps you test marko components within the JEST framework.

Requirements

Your project needs to have jest@^23 and marko@^4.5 installed. Within your regular JEST configuration, you need to specify a transform for *.marko files:

...
"transform": {
  ...
  "^.+\\.marko$": "<rootDir>/node_modules/marko-jest/preprocessor.js"
}

Configuration

In the global JEST object, you can pass a tester configuration:

"global": {
  ...
  "tester": {
    "shallow": false
  }
}
  • shallow - You can turn off shallow rendering by passing false here. That way marko won't isolate any component test. (Default: true)

Usage

marko-tester returns a function for you to use. Pass a relative path to a marko component file and you will receive a render method and fixtures method/object. By default this will run JEST SnapShots test for the fixtures of the component.

  • render is a method that renders a component with a given input and mounts it to document.body. The mounted component instance is returned.

  • fixtures is an object by default. It contains all the fixtures that are found within the __snapshots__ folder for the component. If a withoutFixtures option is passed, fixtures will also be a function that will run JEST SnapShots test for your fixtures. You will still be able to get any fixture content by the filename: fixtures[FixtureFileName].

Example

You can find examples in the tests folder. The boilerplate looks like this:

const { render } = require('marko-tester')('../index.marko');

describe('When component is rendered', () => {
  let component;

  beforeEach(() => {
    component = render(fixtures.default);
  });

  afterEach(() => {
    component.destroy();
  });

  ...your assertions...
});

References

Thanks

Licence

MIT

install

npm i marko-tester

Downloadsweekly downloads

3,725

version

9.1.0

license

MIT

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability