Jasmine Cheat Sheet

  



Karma jasmine angular cheat sheet

A short guide to all the exported functions in DOM Testing Library

  1. CSS Cheat Sheet contains the most common style snippets: CSS gradient, background, button, font-family, border, radius, box and text shadow generators, color picker and more. All these and other useful web designer tools can be found on a single page.
  2. This cheat sheet co-authored by Ravi Kiran and Suprotim Agarwal, aims at providing a quick reference to the most commonly used features in AngularJS. It will also make you quickly productive with Angular. This article is from the Free DNC Magazine for.Net and JavaScript developers.
  3. INSTANT POT CHEAT SHEETINSTANT POT CHEAT SHEET FOR ALL ITEMS LISTED: fresh (not frozen) Pressure: high Setting: manual Liquid: minimum 1 cup water. Basmati, Jasmine Rice, Brown Rice, White Rice, Wild Spaghetti Steel Cut Oats DRIED rice & grains LIQUID RELEASE RATIO 1:3 1:2 1:2 1:2 1:1.75 1:2 1:1 1:2.5 1:4 1:1 1:1 1:1 1:1 1:2 1:2 1:3 QPR QPR.

Jasmine is my testing framework of choice when I’m writing Angular. And I was just getting used to all those spy methods with the help of Toby Ho’s cheat sheet, and then Jasmine 2 came along and changed all the method names. So here’s an updated cheat sheet for spying with Jasmine 2. Create a spy Spy on an existing method.

Queries#

See Which query should I use?

No Match1 Match1+ MatchAwait?
getBythrowreturnthrowNo
findBythrowreturnthrowYes
queryBynullreturnthrowNo
getAllBythrowarrayarrayNo
findAllBythrowarrayarrayYes
queryAllBy[]arrayarrayNo
  • ByLabelText find by label or aria-label text content
    • getByLabelText
    • queryByLabelText
    • getAllByLabelText
    • queryAllByLabelText
    • findByLabelText
    • findAllByLabelText
  • ByPlaceholderText find by input placeholder value
    • getByPlaceholderText
    • queryByPlaceholderText
    • getAllByPlaceholderText
    • queryAllByPlaceholderText
    • findByPlaceholderText
    • findAllByPlaceholderText
  • ByText find by element text content
    • getByText
    • queryByText
    • getAllByText
    • queryAllByText
    • findByText
    • findAllByText
  • ByDisplayValue find by form element current value
    • getByDisplayValue
    • queryByDisplayValue
    • getAllByDisplayValue
    • queryAllByDisplayValue
    • findByDisplayValue
    • findAllByDisplayValue
  • ByAltText find by img alt attribute
    • getByAltText
    • queryByAltText
    • getAllByAltText
    • queryAllByAltText
    • findByAltText
    • findAllByAltText
  • ByTitle find by title attribute or svg title tag
    • getByTitle
    • queryByTitle
    • getAllByTitle
    • queryAllByTitle
    • findByTitle
    • findAllByTitle
  • ByRole find by aria role
    • getByRole
    • queryByRole
    • getAllByRole
    • queryAllByRole
    • findByRole
    • findAllByRole
  • ByTestId find by)
  • configure change global options:configure({testIdAttribute: 'my-data-test-id'})

Text Match Options#

Given the following HTML:

Will find the div:

getByText(container,'Hello World')// full string match

Karma Jasmine Angular Cheat Sheet

getByText(container,'llo Worl',{ exact:false})// substring match
getByText(container,'hello world',{ exact:false})// ignore case
// Matching a regex:
getByText(container,/world/i)// substring match, ignore case
getByText(container,/^hello world$/i)// full string match, ignore case
getByText(container,/Hello W?oRlD/i)// advanced regex
// Matching with a custom function:
getByText(container,(content, element)=> content.startsWith('Hello'))

Jasmine Cheat Sheet

Given a button that updates the page after some time:

// Click button
const items =awaitfindByText(node,/Item #[0-9]: /)

Protractor Jasmine Cheat Sheet

})

jQuery Matchers

Only for tags that have checked attribute.

Checks for child DOM elements or text.

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.

Checks to see if the matched element is attached to the DOM.

Check to see if the set of matched elements matches the given selector.

true if the DOM contains the element.

Only for tags that have selected attribute.

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

true if element exists in or out of the DOM.

Attribute value is optional, if omitted it will check only if attribute exists.

If event has been triggered on selector.

If event has been triggered on selector.

toHaveBeenTriggeredOnAndWith(selector, extraParameters)

If event has been triggered on selector and with extraParameters.

If event has been prevented on selector.

If event has been prevented on selector.

Open mac app store. Value is optional, if omitted it will check only if an entry for that key exists.

Property value is optional, if omitted it will check only if property exists.

Accepts a String or regular expression.

Only for elements on which val can be called (input, textarea, etc).