亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

在node js中編寫用于搜索記錄和排序記錄的單元測試

在node js中編寫用于搜索記錄和排序記錄的單元測試

神不在的星期二 2022-11-11 13:23:58
剛接觸編寫單元測試,只是想問一下下面的示例代碼編寫單元測試的例子是什么,比如什么時候使用斷言?以及如何在下面的代碼中測試過濾器?謝謝你。我在大學測試中使用摩卡咖啡#當前單元測試代碼.....      it('load the hook', () => {        assert.ok(search, 'Load the hook');      });          it('searches for record and sort', async () => {            const search_key = "Rajesh"            const people = await People.find({          query: {            $limit: 25,            $skip: 0,            $sort: {              'people': 1,            },            $or: [{              name: {                $like: search_key,              },            }],          },        });      });
查看完整描述

1 回答

?
慕絲7291255

TA貢獻1859條經驗 獲得超6個贊

正如我們所討論的,我添加了用于按名稱檢查過濾器和排序的測試用例。對于排序,您可以使用 chai-sorting 包:npm install chai-sorted. 您需要根據下面的評論對代碼進行一些調整。希望它會有所幫助


it('searches for record and sort', async () => {

    const search_key = "Rajesh";

    const limit = 25;

    //you will need to have `data` variable and link `search_key` and `limit` with it somehow

    const people = await search_data()(data);

    if (people) {

      //length must be less than or equal to `limit`

      expect(people.length).to.be.at.most(limit);


      // check sorting by name. you can change it as descendingBy if you need

      expect(people).to.be.ascendingBy("name");


      people.forEach(person => { 

        //checking filter for name

        expect(person.name).to.have.string(search_key);

      });

    }        

});


查看完整回答
反對 回復 2022-11-11
  • 1 回答
  • 0 關注
  • 105 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號