2.7.0 • Published 4 years ago

vue-hubble v2.7.0

Weekly downloads
206
License
MIT
Repository
github
Last release
4 years ago

Vue Hubble

Build npm.io npm.io npm.io npm.io Maintainability

A better way to select elements for UI testing in Vue.

Vue Hubble makes it simple to add selectors (only in your testing environment) and target component elements in tests without worrying about collisions, extraneous classes, etc.

Install

yarn add -D vue-hubble
# or
npm i -D vue-hubble
import VueHubble from 'vue-hubble';

Vue.use(VueHubble, options);

Usage

Implementation

<template>
  <div v-hubble="'attribute-selector'"></div>
  <div v-hubble:class="'class-selector'" class="existing-class"></div>
  <div v-hubble:id="'id-selector'" id="existing-id"></div>
</template>

<!-- Resulting HTML when NODE_ENV === 'test' -->

<!--(vue-hubble) attribute-selector-->
<div attribute-selector></div>
<!--//(vue-hubble) attribute-selector-->

<!--(vue-hubble) class-selector-->
<div class="existing-class class-selector"></div>
<!--//(vue-hubble) class-selector-->

<!--(vue-hubble) id-selector-->
<div id="id-selector"></div>
<!--//(vue-hubble) id-selector-->

Namespacing

Hubble gives you the ability to namespace all selectors in a given component. Namespacing is recursive up the component tree, ignoring missing or empty namespace values. This feature is enabled by default, but can be disabled via install options.

<!-- Form Component (child) -->
<template>
  <div v-hubble="'attribute-selector'"></div>
</template>

<script>
  export default {
    hubble: {
      namespace: 'form'
    }
  };
</script>

<!-- Login Component (parent) -->
<template>
  <form />
</template>

<script>
  export default {
    components: {
      Form
    },
    hubble: {
      namespace: 'login'
    }
    /**
     * Or shorthand...
     * hubble: 'login'
     **/
  };
</script>

<!-- Resulting HTML when NODE_ENV equals correct environment (see install options)-->

<!--(vue-hubble) login--form--attribute-selector-->
<div login--form--attribute-selector></div>
<!--//(vue-hubble) login--form--attribute-selector-->

Writing Tests

Examples

describe('directive.js', () => {
  it('should add an attribute selector', () => {
    const wrapper = mount({
      template: '<div><span v-hubble="\'selector\'"></span></div>'
    });

    expect(wrapper.contains('[selector]')).toBe(true);
  });
});

Install Options

NameTypeDefaultDescription
defaultSelectorTypeStringattrDefines the selector type if not passed into the directive v-hubble:attr
enableCommentsBooleantrueEnables or disables comments around elements with hubble selectors
enableDeepNamespacingBooleantrueEnables or disables auto recursive namespacing
environmentString or ArraytestDefines the environment(s) in which these selectors are added
prefixStringPrefixes all selectors with the value and --, if value exists. For example, if prefix = 'qa', all selectors well begin withqa--

Lint

yarn lint

Test

yarn test

Build Dist

yarn build

How to Contribute

Pull Requests

  1. Fork the repository
  2. Create a new branch for each feature or improvement
  3. Send a pull request from each feature branch to the develop branch

License

MIT

2.5.0

4 years ago

2.4.0

4 years ago

2.7.0

4 years ago

2.6.0

4 years ago

2.3.0

4 years ago

2.2.0

4 years ago

2.1.3

4 years ago

2.1.2

4 years ago

2.1.1

4 years ago

2.1.0

4 years ago

2.0.1

4 years ago

2.0.0

4 years ago

1.1.1

4 years ago

1.1.0

4 years ago

0.3.3

5 years ago

0.3.2

5 years ago

0.3.1

5 years ago

0.3.0

5 years ago

0.2.1

5 years ago

0.2.0

5 years ago

0.1.11

5 years ago

0.1.10

5 years ago

0.1.9

5 years ago

0.1.8

5 years ago

0.1.7

5 years ago

0.1.6

5 years ago

0.1.5

5 years ago

0.1.4

5 years ago

0.1.3

5 years ago

0.1.2

5 years ago

0.1.1

5 years ago

0.0.2

5 years ago