npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

protractor-jasmine-matchers

v0.0.3

Published

Custom jasmine matchers to make your protractor's tests more efficient and readable

Downloads

29

Readme

Protractor-Jasmine-Matchers

Protractor-Jasmine-Matchers is a library which provides a light-weight matchers for the Protractor and Jasmine test frameworks.

Table of Contents

Getting Started

Installation

To use Protractor-Jasmine-Matchers in your project, run:

npm i --save-dev protractor-jasmine-matchers

Importing and Adding

Add the protractor-jasmine-matchers module to the your protractor.config.js file in the onPrepare function and wrap it into the beforeEach function.

protractor.config.js

// importing module
const customMatchers = require('protractor-jasmine-matchers');

exports.config = {
    onPrepare() {

        // add matchers in the beforeEach hook
        beforeEach(() => jasmine.addMatchers(customMatchers))
    }
}

protractor.config.ts

// importing module
import * as customMatchers from 'protractor-jasmine-matchers'

exports.config = {
    onPrepare() {

        // add matchers in the beforeEach hook
        beforeEach(() => jasmine.addMatchers(customMatchers))
    }
}

Also you can add the protractor-jasmine-matchers module directly in your test.

// importing module
const customMatchers = require('protractor-jasmine-matchers');

describe('Test suite', () => {

    // add matchers in the beforeEach hook
    beforeEach(() => jasmine.addMatchers(customMatchers))

    it('should verify', () => {
        ...
    });
});

Also, if you are faced with the TypeScript compilation errors when running your tests, add the typeRoots entry in the tsconfig.json, with the right order:

{
  "compilerOptions": {
    "typeRoots": [
      "./node_modules/protractor-jasmine-matchers", 
      "./node_modules/@types"
    ],
  }
}

Usage

Example - asserting element's text with toHaveText function that comes with the protractor-jasmine-matchers library.

Without the protractor-jasmine-matchers library:

expect(await element.getText()).toBe('Some text');

After adding the protractor-jasmine-matchers library:

await expect(element).toHaveText('Some text');

Example - asserting element's value with toHaveValue function that comes with the protractor-jasmine-matchers library.

Without the protractor-jasmine-matchers library:

expect(await element.getAttribute('value')).toBe('Some value');

After adding the protractor-jasmine-matchers library:

await expect(element).toHaveValue('Some value');

API

toBeDisplayed - verifies that element is displayed on the page.

Example:

await expect(element).toBeDisplayed();

not.toBeDisplayed - it is the inverse of the toBeDisplayed function.

Example:

await expect(element).not.toBeDisplayed();

toBePresent - verifies that element is present in the DOM.

Example:

await expect(element).toBePresent();

not.toBePresent - it is the inverse of the toBePresent function.

Example:

await expect(element).not.toBePresent();

toContainText - verifies that element contains text.

Example:

await expect(element).toContainText('Expected text');

not.toContainText - it is the inverse of the toContainText function.

Example:

await expect(element).not.toContainText('Expected text');

toHaveText - verifies element's text.

Example:

await expect(element).toHaveText('Expected text');

toContainValue - verifies that element contains value.

Example:

await expect(element).toContainValue('Expected value');

not.toContainValue - it is the inverse of the toContainValue function.

Example:

await expect(element).not.toContainValue('Expected value');

toHaveValue - verifies element's value.

Example:

await expect(element).toHaveValue('Expected value');

toBeDisabled - verifies that element is disabled.

Example:

await expect(element).toBeDisabled();

not.toBeDisabled - it is the inverse of the toBeDisabled function.

Example:

await expect(element).not.toBeDisabled();

toBeSelected - verifies that element is selected(checked).

Example:

await expect(element).toBeSelected();

not.toBeDisabled - it is the inverse of the toBeSelected function.

Example:

await expect(element).not.toBeSelected();

toHaveLink - verifies element's link(href attribute).

Example:

await expect(element).toHaveLink('https://expected-link.com/');

toHaveClassName - verifies element's class names.

Example:

await expect(element).toHaveClass('expected-css-name');

toHaveLength - verifies element's length.

Example:

await expect(elements).toHaveLength(3);

License

Protractor-Jasmine-Matchers is MIT licensed.