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

angular-jasmine-matchers

v0.0.1

Published

Matchers for Jasmine Testing in AngularJS

Downloads

6

Readme

Angular Matchers

angular matchers provides a set of matchers for the Jasmine JavaScript Testing Framework:

  • a set of custom matchers for Angular framework that are meant to make your testing a little bit easier

Angular matchers

jasmine-jquery provides following custom matchers (in alphabetical order):

  • toBe(jQuerySelector)

    • e.g. expect($('<div id="some-id"></div>')).toBe('div')
    • e.g. expect($('<div id="some-id"></div>')).toBe('div#some-id')
  • toBeChecked()

    • only for tags that have checked attribute
    • e.g. expect($('<input type="checkbox" checked="checked"/>')).toBeChecked()
  • toBeEmpty()

    • Checks for child DOM elements or text.
  • toBeHidden()

    Elements can be considered hidden for several reasons:

    • They have a CSS display value of none.
    • They are form elements with type equal to hidden.
    • Their width and height are explicitly set to 0.
    • An ancestor element is hidden, so the element is not shown on the page.
  • toHaveCss(css)

    • e.g. expect($('<div style="display: none; margin: 10px;"></div>')).toHaveCss({display: "none", margin: "10px"})
    • e.g. expect($('<div style="display: none; margin: 10px;"></div>')).toHaveCss({margin: "10px"})
  • toBeSelected()

    • only for tags that have selected attribute
    • e.g. expect($('<option selected="selected"></option>')).toBeSelected()
  • toBeVisible()

    • Elements are considered visible if they consume space in the document. Visible elements have a width or height that is greater than zero.
  • toContain(jQuerySelector)

    • e.g. expect($('<div><span class="some-class"></span></div>')).toContain('span.some-class')
  • toExist()

  • toHaveAttr(attributeName, attributeValue)

    • attribute value is optional, if omitted it will check only if attribute exists
  • toHaveProp(propertyName, propertyValue)

    • property value is optional, if omitted it will check only if property exists
  • toHaveClass(className)

    • e.g. expect($('<div class="some-class"></div>')).toHaveClass("some-class")
  • toHaveData(key, value)

    • value is optional, if omitted it will check only if an entry for that key exists
  • toHaveHtml(string)

    • e.g. expect($('<div><span></span></div>')).toHaveHtml('<span></span>')
  • toContainHtml(string)

    • e.g. expect($('<div><ul></ul><h1>header</h1></div>')).toContainHtml('<ul></ul>')
  • toHaveId(id)

    • e.g. expect($('<div id="some-id"></div>')).toHaveId("some-id")
  • toHaveText(string)

    • accepts a String or regular expression
    • e.g. expect($('<div>some text</div>')).toHaveText('some text')
  • toHaveValue(value)

    • only for tags that have value attribute
    • e.g. expect($('<input type="text" value="some text"/>')).toHaveValue('some text')
  • toBeDisabled()

    • e.g. expect('<input type='submit' disabled='disabled'/>').toBeDisabled()
  • toBeFocused()

    • e.g. expect($('<input type='text' />').focus()).toBeFocused()
  • toHandle(eventName)

    • e.g. expect($form).toHandle("submit")
  • toHandleWith(eventName, eventHandler)

    • e.g. expect($form).toHandleWith("submit", yourSubmitCallback)

The same as with standard Jasmine matchers, all of above custom matchers may be inverted by using .not prefix, e.g.:

expect($('<div>some text</div>')).not.toHaveText(/other/)

Dependencies

angular matchers was tested with Jasmine 1.2 and jQuery 1.8 on FF, Chrome, and Safari. There is a high chance it will work with older versions and other browsers as well, but I don't typically run test suite against them when adding new features.

Cross domain policy problems under Chrome

Newer versions of Chrome don't allow file:// URIs read other file:// URIs. In effect, jasmine-jquery cannot properly load fixtures under some versions of Chrome. An override for this is to run Chrome with a switch --allow-file-access-from-files.

Under Windows 7, you have to launch C:\Users\[UserName]\AppData\Local\Google\Chrome[ SxS]\Application\chrome.exe --allow-file-access-from-files

Writing the Code

  • Get the code right.
  • Include tests that fail without your code, and pass with it.
  • Update the (surrounding) documentation, examples elsewhere, and the guides: whatever is affected by your contribution.
  • Follow the conventions in the source you see used already, basically npm coding style

If you can, have another developer sanity check your change

Install via Bower

Now offers bower support. bower install angularjs-jasmine-matchers --save

Build status

Build Status