1. jasmine-jquery-matchers
Add a set of custom matchers for HTML and CSS related checks, using jQuery.
jasmine-jquery-matchers
Package: jasmine-jquery-matchers
Created by: unindented
Last modified: Sun, 19 Jun 2022 03:46:37 GMT
Version: 2.1.1
License: MIT
Downloads: 3,950
Repository: https://github.com/unindented/custom-jquery-matchers

Install

npm install jasmine-jquery-matchers
yarn add jasmine-jquery-matchers

jasmine-jquery-matchers Version

List of matchers

  • toExist
  • toHaveLength
  • toHaveId
  • toHaveClass
  • toHaveTag
  • toHaveAttr
  • toHaveProp
  • toHaveText
  • toHaveData
  • toHaveValue
  • toHaveCss
  • toBeChecked
  • toBeDisabled
  • toBeEmpty
  • toBeHidden
  • toBeSelected
  • toBeVisible
  • toBeFocused
  • toBeInDom
  • toBeMatchedBy
  • toHaveDescendant
  • toHaveDescendantWithText

Installation

Just run:

 $ npm install --save-dev jasmine-jquery-matchers

Usage

Load these matchers in a beforeEach block, and then use them like any other matcher:

 expect(this.$el).toHaveText('Hello world!');

TypeScript

This package includes the necessary declarations for TypeScript. Just make sure they get loaded in your project, for example by adding the package name to the types field in your tsconfig.json:

 {
  "compilerOptions": {
    "module": "commonjs",
    "target": "es5",
    "types": [
      "jasmine",
      "jasmine-jquery-matchers"
    ]
  }
}

Then just load the matchers at runtime in your tests:

 import * as matchers from 'jasmine-jquery-matchers';

describe('My suite', function () {
  beforeEach(function () {
    jasmine.addMatchers(matchers);
  });

  it('passes if the element has the specified class', function () {
    expect($('<div class="some-class"></div>')).toHaveClass('some-class');
  });
});

ES2015

If you are using the new module syntax, import all exported matchers:

 import * as matchers from 'jasmine-jquery-matchers';

describe('My suite', function () {
  beforeEach(function () {
    jasmine.addMatchers(matchers);
  });

  it('passes if the element has the specified class', function () {
    expect($('<div class="some-class"></div>')).toHaveClass('some-class');
  });
});

Note that jasmine-jquery-matchers does not have a default export!

AMD/CommonJS

If you are using AMD or CommonJS, require normally:

 var matchers = require('jasmine-jquery-matchers');

describe('My suite', function () {
  beforeEach(function () {
    jasmine.addMatchers(matchers);
  });

  it('passes if the element has the specified class', function () {
    expect($('<div class="some-class"></div>')).toHaveClass('some-class');
  });
});

Global

Otherwise, use window['jasmine-jquery-matchers']:

 var matchers = window['jasmine-jquery-matchers'];

describe('My suite', function () {
  beforeEach(function () {
    jasmine.addMatchers(matchers);
  });

  it('passes if the element has the specified class', function () {
    expect($('<div class="some-class"></div>')).toHaveClass('some-class');
  });
});

RELATED POST

10 Must-Know Windows Shortcuts That Will Save You Time

10 Must-Know Windows Shortcuts That Will Save You Time

Arrays vs Linked Lists: Which is Better for Memory Management in Data Structures?

Arrays vs Linked Lists: Which is Better for Memory Management in Data Structures?

Navigating AWS Networking: Essential Hacks for Smooth Operation

Navigating AWS Networking: Essential Hacks for Smooth Operation

Achieving Stunning Visuals with Unity's Global Illumination

Achieving Stunning Visuals with Unity's Global Illumination

Nim's Hidden Gems: Lesser-known Features for Writing Efficient Code

Nim's Hidden Gems: Lesser-known Features for Writing Efficient Code