--- title: its comments: true description: '' --- Get a property on the previously yielded subject. {% note info %} If you want to call a function on the previously yielded subject, use [`cy.invoke`](https://on.cypress.io/api/invoke). {% endnote %} # Syntax ```javascript .its(propertyName) ``` ## Usage `.its()` requires being chained off another cy command that *yields* an object with properties. **{% fa fa-check-circle green %} Valid Usage** ```javascript cy.wrap({width: '50'}).its('width') // Get the 'width' property cy.location().its('href') // Get the 'href' property ``` **{% fa fa-exclamation-triangle red %} Invalid Usage** ```javascript cy.its('window') // Errors, cannot be chained off 'cy' cy.clearCookies().its('length') // Errors, 'clearCookies' does not yield Object ``` ## Arguments **{% fa fa-angle-right %} propertyName** ***(String)*** Name of property or nested properties (with dot notation) to get. ## Yields `.invoke()` yields the value of the property. ## Timeout # Examples ## Plain Objects **Get property** ```javascript cy.wrap({foo: 'bar'}).its('foo').should('eq', 'bar') // true ``` ## DOM Elements **Get the `length` property of a DOM element** ```javascript cy .get('ul li') // this returns us the jquery object .its('length') // calls the 'length' property returning that value .should('be.gt', 2) // ensure this length is greater than 2 }) ``` ## Strings **Get `length` of title** ```javascript cy.title().its('length').should('eq', 24) ``` ## Functions **Get function property** ```javascript var fn = function(){ return 'bar' } cy.wrap({foo: fn}).its('foo').should('be.a', 'function') ``` **Inspect function** You can access functions to then drill into their own properties instead of invoking them. ```javascript // Your app code // a basic Factory constructor var Factory = function(arg){ ... } Factory.create = function(arg){ return new Factory(arg) } // assign it to the window window.Factory = Factory ``` ```javascript cy .window() // yields window object .its('Factory') // yields Factory function .invoke('create', 'arg') // now invoke properties on it ``` {% note info %} [Check out our example recipe on testing `window.fetch` using `.its()`](https://github.com/cypress-io/cypress-example-recipes/blob/master/cypress/integration/spy_stub_clock_spec.js) {% endnote %} ## Nested Properties You can drill into nested properties by using **dot notation**. ```javascript var user = { contacts: { work: { name: 'Kamil' } } } cy.wrap(user).its('contacts.work.name').should('eq', 'Kamil') // true ``` # Command Log **Get `responseBody` of aliased route** ```javascript cy .server() .route(/comments/, 'fixture:comments.json').as('getComments') .get('#fetch-comments').click() .wait('@getComments') .its('responseBody') .should('deep.eq', [ {id: 1, comment: 'hi'}, {id: 2, comment: 'there'} ]) ``` The commands above will display in the command log as: ![screen shot 2016-05-24 at 12 39 40 pm](https://cloud.githubusercontent.com/assets/1268976/15512229/d512cbb4-21ac-11e6-9a9a-5d358ae4fe4b.png) When clicking on `its` within the command log, the console outputs the following: ![screen shot 2016-05-24 at 12 40 17 pm](https://cloud.githubusercontent.com/assets/1268976/15512225/d14723cc-21ac-11e6-88d5-39ffe6c0a195.png) # See also - [invoke](https://on.cypress.io/api/invoke) - [wrap](https://on.cypress.io/api/wrap) - [then](https://on.cypress.io/api/then)