1

I'm using Chai to write some unit tests. I'm doing two assertions on an array of strings. I'm asserting the array is an actual array & it contains only strings. Both assertions are passing & working properly. However, in the second assertion, I'm getting this warning: eslint-disable-next-line no-unused-expressions. I'm unsure of how to fix this warning before ignoring it. How can I accomplish this?

import { assert, expect } from 'chai';
import { prContributors } from './pr-contributors.js';

describe('Pull Request Contributor List array', () => {
  it('should be an array', () => {
    assert.isArray(prContributors, 'prContributors is an array');
  });

  it('should contain only strings', () => {
    // eslint-disable-next-line no-unused-expressions
    expect(prContributors.every((contributor) => typeof contributor === 'string')).to.be.true;
  });
});

I was able to fix it by storing the results in a variable & print it, but I don't want to add an unnecessary console.log() & I traded a warning for another.

it('should contain only strings', () => {
    const result = prContributors.every((contributor) => typeof contributor === 'string');
    console.log(result); // now I traded the warning :(
});

I also try this:

it('should contain only strings', () => {
    const result = prContributors.every((contributor) => typeof contributor === 'string');
    expect(result).to.be.true; // still got the warning
});

However, the warning is still there.

Manuel Abascal
  • 5,616
  • 5
  • 35
  • 68
  • Does this answer your question? https://stackoverflow.com/questions/37558795/nice-way-to-get-rid-of-no-unused-expressions-linter-error-with-chai – Lin Du Sep 24 '21 at 01:44

0 Answers0