getgrit / stdlib

The GritQL standard library provides common patterns for refactoring and upgrading code.
https://docs.grit.io/patterns
48 stars 18 forks source link

grit apply chai_to_jest should remove chai imports if exists #209

Open prabirshrestha opened 4 months ago

prabirshrestha commented 4 months ago

Given the following file.

import { expect } from 'chai';

describe('some test suite', function () {
  it('test should exist', function () {
    const test = 'test';
    expect(test).to.equal('test');
  });
});

When running grit apply chai_to_jest it converts the expect methods but the import { expect } from 'chai; is not removed.

import { expect } from 'chai';

describe('some test suite', function () {
  it('test should exist', function () {
    const test = 'test';
    expect(test).toBe('test');
  });
});

Workaround is to manually call remove_import.

grit apply 'remove_import(from=`"chai"`)'