-1

What if I want to validate a result from an array response!

Response:

({ id: '612d56952ca01806398dac1f', lastUpdated: '2021-08-30T22:07:17.099Z', userToken: 'public', data: Object({ createdOn: '2021-08-30T22:07:16.916Z', lastUpdatedBy: null, userId: '60f469cf784379051298e96d', displayName: 'Nadia', postText: 'post text sample', postImages: 'image test', pluginInstance: Object({ pluginInstanceId: '1627334094776-047554258642281355', pluginInstanceTitle: 'communityFeedPlugin' }), isPublic: true, _buildfire: Object({ index: Object({ array1: [ Object({ string1: 'userId_60f469cf784379051298e96d' }), Object({ string1: 'displayName_nadia' }), Object({ string1: 'pluginTitle_communityfeedplugin' }), Object({ string1: 'isPublic_1' }) ] }) }) }) }), Object({ id: '612d564dfabce50627bdb5db', lastUpdated: '2021-08-30T22:06:05.699Z', userToken: 'public', data: Object({ createdOn: '2021-08-30T22:06:05.500Z', lastUpdatedBy: null, userId: '60f469cf784379051298e96d', displayName: 'Nadia', postText: 'post text sample', postImages: 'image test', pluginInstance: Object ...

Tried the following but did not work:

it('Get all posts' , function(done){
    Posts.getPosts('publicPosts' ,(err,resp) =>{
        expect(resp).toContain(jasmine.objectContaining({
            id: '612d50bafabce50627bdb538',
            postText:'post text sample',
            userId: '60f469cf784379051298e96d',
            isPublic: true
          }));
        done();
    });
});

1 Answers1

0

this did not work too:

it('Get all posts' , function(done){
    Posts.getPosts({publicPosts : true},(err,resp) => {
        expect(resp.data).toEqual(jasmine.objectContaining({
            userId: authManager.currentUser._id,
            isPublic: true
          }));
      done();
    });   
});

with resp.data I am getting undefined , and without data it will fail

  • Please provide additional details in your answer. As it's currently written, it's hard to understand your solution. – Community Aug 31 '21 at 00:12