预期{}是chai中的对象

时间:2018-08-29 23:24:49

标签: javascript express promise mocha chai

describe('YoutubeService.getTrendingVideos', function() {
    it('should resolve to expectedResult', function() {
        const params = {
            id: 'O2uf_RveI80',
            title:
                'Shambho Shankara Full Movie - 2018 Telugu Full Movies - Shakalaka Shankar, Karunya',
            thumbnail: 'https://i.ytimg.com/vi/O2uf_RveI80/hqdefault.jpg',
            publishedAt: '2 days ago',
        };
        return chai.assert.isObject(getTrends.YoutubeService.getVideoDetails(params),'object match found');
   });

上面是用chai编写的测试断言,用于测试函数是否正在重现对象。

功能如下:

export class YoutubeService {
  getTrendingVideos(country) {
    var params = {
      part: 'snippet',
      chart: 'mostPopular',
      regionCode: country, // should be replaced with country code from countryList
      maxResults: '24',
      key: config.youtubeApi.key
    };
    let result = [];
    let promises = [];
    return axios.get('/', {params}).then(function(res){
      result = res.data.items;
      for (var i = 0; i < result.length; i++) {
          result[i] = {
              id: result[i].id,
              title: result[i].snippet.title,
              thumbnail: result[i].snippet.thumbnails.high.url,
              publishedAt: moment(result[i].snippet.publishedAt).fromNow()
          };
          promises.push(YoutubeService.getVideoDetails(result[i]));
      }
        return Promise.all(promises);
    });
  }

  static getVideoDetails(video) {
    let params = {
      part: 'statistics',
      id: video.id,
      key: config.youtubeApi.key
    };

    return axios.get('/', {params}).then(function(res) {
      let result = res.data;
      video.viewCount = result['items'][0].statistics.viewCount;
      video.likeCount = result['items'][0].statistics.likeCount;
      return video;
    });
  }
}

我遇到以下问题:

expected {} to be an object

我该如何解决?我是新来摩卡和柴的人 预先感谢。

0 个答案:

没有答案