0

At consumer level test is :

describe('Listing first level taxonomies', () => {
    before(() => {
        return provider.addInteraction({
            given: 'GET call for first level taxonomies',
            uponReceiving: 'Get object for listing first level 
                            taxonomies',
            withRequest: {
                method: 'GET',
                path: '/api/taxonomies/8061159/taxons?deleted=false',
            },
            willRespondWith: {
                status: 200,
                headers: { 'Content-Type': 'application/json' },
                body: firstChild
            }
        });
    });


const firstChild = eachLike({
'name': like('Geo'),
'taxons': [
    eachLike({
        'id': like(115590),
        'name': like('Africa'),
        'hasChildren':like (false)
    })
  ]
});

When i verify at provider level , I am getting the error as: Expected an Array but got a Hash ({"name"=>"Demo Taxonomy", "taxons"=> [{"id"=>8145188, "name"=>"manojtaxon", "childCategoryName"=>"hello", "hasChildren"=>true} Full error is present at : https://pastebin.com/XvB17SXY

Please help me in resolving the issue What i think is array size is more at provider level thats why it is failing .Though i have added like and eachLike ( Still it has not resolved it ) .

Dolly Agarwal
  • 111
  • 1
  • 6

1 Answers1

0

The problem is your matcher is incorrect:

It should be like this:

const firstChild = like({
  'name': 'Geo',
  'taxons': eachLike({
          'id': 115590,
          'name': 'Africa',
          'hasChildren': false
      })
  });                          

Note the removal of [ and ].

Also, you can avoid the like statements within an eachLike as it is implied by default. If you need to use a different matcher (e.g. a term then you can override that behaviour, but you seem to just be using like here).

Matthew Fellows
  • 3,669
  • 1
  • 15
  • 18
  • Thanks for the response .It worked like this : 'name': like('Geo'), 'taxons': eachLike({ 'id': 115590, 'name': 'Africa', 'hasChildren': false }) } But if i want to add more elements on taxons like taxon[0],taxon[1] how do i that ? I did like this firstChild = { 'name': like('Geo'), 'taxons': eachLike({ 'id': 115590, 'name': 'Africa', 'hasChildren': false },{ 'id': 115578, 'name': 'Asia', 'childCategoryName': 'Country', 'hasChildren': true }) but it fails – Dolly Agarwal Nov 28 '18 at 11:02
  • It's saying it's expecting an array but got a hash. If the provider is returning a single object with `taxons` as an array, change the first `eachLike` to just a `like` – Matthew Fellows Nov 29 '18 at 16:34