Skip to content

Instantly share code, notes, and snippets.

@nickmeehan
Last active August 29, 2015 14:01
Show Gist options
  • Save nickmeehan/b70a3e7ff5261a578240 to your computer and use it in GitHub Desktop.
Save nickmeehan/b70a3e7ff5261a578240 to your computer and use it in GitHub Desktop.
Jasmine Testing Methods

Jasmine Testing Methods

Finding methods for Jasmine testing is a pain in the ass. So I found these. Enjoy!
  • toBe: represents the exact equality (===) operator.

  • toEqual: represents the regular equality (==) operator.

  • toMatch: calls the RegExp match() method behind the scenes to compare string data.

  • toBeDefined: opposite of the JS "undefined" constant.

  • toBeUndefined: tests the actual against "undefined".

  • toBeNull: tests the actual against a null value - useful for certain functions that may return null, like those of regular expressions (same as toBe(null))

  • toBeTruthy: simulates JavaScript boolean casting.

  • toBeFalsy: like toBeTruthy, but tests against anything that evaluates to false, such as empty strings, zero, undefined, etc…

  • toContain: performs a search on an array for the actual value.

  • toBeLessThan/toBeGreaterThan: for numerical comparisons.

  • toBeCloseTo: for floating point comparisons.

  • toThrow: for catching expected exceptions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment