debitoor / chai-subset

"containSubset" object properties matcher for Chai
http://chaijs.com/plugins/chai-subset/
MIT License
82 stars 20 forks source link

Interoperability with chai-as-promised #16

Closed CWSpear closed 9 years ago

CWSpear commented 9 years ago

Does this work with chai-as-promised? It's not working for me, but I could be doing something wrong...

var chai = require('chai');
var chaiAsPromised = require('chai-as-promised');
var chaiSubset = require('chai-subset');
chai.use(chaiAsPromised);
chai.use(chaiSubset);
chai.should();

// later...

return this.getDiscounts({
    promoCode : '',
    siteCode  : 'US',
    skus: [{
        sku: '1234',
        basePrice: 20,
        quantity: 3
    }]
}).should.eventually.containSubset({
    skus: [{
        sku: '1234',
        discounts: [{
            savings: -2.5,
            quantity: 1,
            savingsType: 'adjustment'
        }]
    }]
});

It's saying the actual is:

{
     "_bitField": 268435456
     "_fulfillmentHandler0": [undefined]
     "_progressHandler0": [undefined]
     "_promise0": [undefined]
     "_receiver0": [undefined]
     "_rejectionHandler0": [undefined]
     "_settledValue": { ... }
}

where _settledValue has the value I'm expecting. It looks like it's not looking at the resolved value, the part that the eventually part should (see what I did there?) be doing.

If it indeed doesn't support chai-as-promised, would it be feasible to make it do so?

CWSpear commented 9 years ago

chai.use order matters! I set chai to use chai-as-promised after chai-subset and it works:

// chai.use order matters!
chai.use(chaiSubset);
chai.use(chaiAsPromised);
qfox commented 9 years ago

Thanks! ;-D