2015-07-02 12 views
5

Ho problemi a controllare questo oggetto c'è qualcosa che devo fare per concatenare più istruzioni .to.have.property? Credo che sto solo restituendo il risultato dell'ultimo .to.have.property nel prossimo.Verifica se l'oggetto ha più proprietà

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) 

Sembra che posso usare qualcosa di simile chai-subset per controllare un oggetto. Non c'è modo di incatenarli insieme? Mi dispiacerebbe doverlo fare.

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) 
+1

Non ne so molto, ma sembra che lavori siano in corso. Vedi link https://github.com/chaijs/chai/issues/193 – Elyasin

risposta

2

potrebbe costruire la propria funzione che appena restituisce true/false e ha qualsiasi interfaccia.

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 
Problemi correlati