Testing if an object has several properties

I have a problem checking this object, is there something I need to do to link multiple .to.have.property ? I believe that I simply return the result from the last .to.have.property to the next.

 expect(shopify.formatRequestOptions("shop")) .to.have.property('url', "https://"+settings.shop+"/admin/shop.json") .to.have.property('method', "GET") .to.have.deep.property('headers.X-Shopify-Access-Token', settings.accessToken) 

It seems I can use something like chai-subset to validate an object. There is no way to tie them together? I would not want to do this.

 var result = shopify.formatRequestOptions("shop") expect(result).to.have.property('url', "https://"+settings.shop+"/admin/shop.json") expect(result).to.have.property('method', "GET") expect(result).to.have.deep.property('headers.X-Shopify-Access-Token', settings.accessToken) 
+5
source share
1 answer

It can create its own function that returns true / false and has any interface.

 let example = { 'name': 'thomas' } let hasAllProps = (obj, props) => { let propsTrue = _.chain(props) .map(prop => _.has(obj, prop)) .without(false) .value() return (propsTrue.length === props.length) } console.log(hasAllProps(example, ['name'])) // true console.log(hasAllProps(example, ['age'])) // false 
+2
source

All Articles