Verify empty object with Jest (extended)
Install jest-extended (npm install --save-dev jest-extended)
and use the toBeEmpty assertion as in the following example:
const { toBeEmpty } = require('jest-extended');
expect.extend({ toBeEmpty });
describe('setFulltextSearchTermsFilter', () => {
test('returns filter without $text when fulltextSearchTerms is empty', () => {
const fulltextSearchTerms = [];
const filter = {};
const searchInclude = 'any';
expect(searchUtils.setFulltextSearchTermsFilter(fulltextSearchTerms, filter, searchInclude)).toBeEmpty();
});
});
Use .toBeEmpty when checking if a String '', Array [], Object {}, or Iterable is empty. Because toBeEmpty supports checking for emptiness of Iterables, you can use it to check whether a Map, or Set is empty, as well as checking that a generator yields no values.
Project: codever - File: search.utils.spec.js
Reference - https://jest-extended.jestcommunity.dev/docs/matchers/tobeempty
Shared with from Codever.
👉 Use the Copy to mine
functionality to copy this snippet to your own personal collection and easy manage
your code snippets.
Codever is open source on Github ⭐🙏