vendredi 11 octobre 2019

how to make sure all items in an array of objects has all required keys in mocha?

i'm new in testing and i have a result of array of objects and i want to make sure each item in an array has required properties, the result is like this:

// result_threads = [{a:1,b:2},{a:3,b:4}]

and i want to make a test like this:

chai_module
      .request(server)
      .get(`/api/threads/${test_board_id}`)
      .end((get_threads_error, response) => {
        const { status: actual_status } = response;
        const { threads: result_threads } = response.body
        // THE TEST I WANT TO MAKE
        assert.isArray(result_threads).to.contain.an.item.hasAllKeys(['a','b']);


        done();
      });

how do i make sure that an item in an array has all keys required?

Aucun commentaire:

Enregistrer un commentaire