angular matchers provides a set of matchers for the Jasmine JavaScript Testing Framework:
jasmine-jquery provides following custom matchers (in alphabetical order):
toBe(jQuerySelector)
expect($('<div id="some-id"></div>')).toBe('div')
expect($('<div id="some-id"></div>')).toBe('div#some-id')
toBeChecked()
expect($('<input type="checkbox" checked="checked"/>')).toBeChecked()
toBeEmpty()
toBeHidden()
Elements can be considered hidden for several reasons:
display
value of none
.type
equal to hidden
.width
and height
are explicitly set to 0
.toHaveCss(css)
expect($('<div style="display: none; margin: 10px;"></div>')).toHaveCss({display: "none", margin: "10px"})
expect($('<div style="display: none; margin: 10px;"></div>')).toHaveCss({margin: "10px"})
toBeSelected()
expect($('<option selected="selected"></option>')).toBeSelected()
toBeVisible()
toContain(jQuerySelector)
expect($('<div><span class="some-class"></span></div>')).toContain('span.some-class')
toExist()
toHaveAttr(attributeName, attributeValue)
toHaveProp(propertyName, propertyValue)
toHaveClass(className)
expect($('<div class="some-class"></div>')).toHaveClass("some-class")
toHaveData(key, value)
toHaveHtml(string)
expect($('<div><span></span></div>')).toHaveHtml('<span></span>')
toContainHtml(string)
expect($('<div><ul></ul><h1>header</h1></div>')).toContainHtml('<ul></ul>')
toHaveId(id)
expect($('<div id="some-id"></div>')).toHaveId("some-id")
toHaveText(string)
expect($('<div>some text</div>')).toHaveText('some text')
toHaveValue(value)
expect($('<input type="text" value="some text"/>')).toHaveValue('some text')
toBeDisabled()
expect('<input type='submit' disabled='disabled'/>').toBeDisabled()
toBeFocused()
expect($('<input type='text' />').focus()).toBeFocused()
toHandle(eventName)
expect($form).toHandle("submit")
toHandleWith(eventName, eventHandler)
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/)
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.
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
If you can, have another developer sanity check your change
Now offers bower support. bower install angularjs-jasmine-matchers --save