Skip to content

Commit

Permalink
Merge pull request #12 from ReactiveX/minko/fix-frompromise
Browse files Browse the repository at this point in the history
fix(rules): proper migration of fromPromise and _throw
  • Loading branch information
benlesh committed Apr 19, 2018
2 parents 651b5b1 + a744151 commit 5c54550
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/updateRxjsImportsRule.ts
Expand Up @@ -163,6 +163,18 @@ const ImportReplacements = [
newPath: 'rxjs',
newSymbol: 'NEVER'
},
{
path: 'rxjs/observable/fromPromise',
symbol: 'fromPromise',
newPath: 'rxjs',
newSymbol: 'from'
},
{
path: 'rxjs/observable/throw',
symbol: '_throw',
newPath: 'rxjs',
newSymbol: 'throwError'
},
{
path: 'rxjs/Subscription',
symbol: 'AnonymousSubscription',
Expand Down
72 changes: 72 additions & 0 deletions test/updateRxjsImportsRule.spec.ts
Expand Up @@ -293,5 +293,77 @@ describe('update-rxjs-imports', () => {

assertReplacements(err as RuleFailure[], source, after);
});

it('should migrate fromPromise to from', () => {
const source = `
import { fromPromise } from 'rxjs/observable/fromPromise';
`;
const after = `
import { from as fromPromise } from 'rxjs';
`;

const err = assertFailures('update-rxjs-imports', source, [
{
startPosition: {
line: 1,
character: 17
},
endPosition: {
line: 1,
character: 28
},
message: 'imported symbol no longer exists'
},
{
startPosition: {
line: 1,
character: 37
},
endPosition: {
line: 1,
character: 64
},
message: 'outdated import path'
}
]);

assertReplacements(err as RuleFailure[], source, after);
});

it('should migrate fromPromise to from', () => {
const source = `
import { _throw } from 'rxjs/observable/throw';
`;
const after = `
import { throwError as _throw } from 'rxjs';
`;

const err = assertFailures('update-rxjs-imports', source, [
{
startPosition: {
line: 1,
character: 17
},
endPosition: {
line: 1,
character: 23
},
message: 'imported symbol no longer exists'
},
{
startPosition: {
line: 1,
character: 32
},
endPosition: {
line: 1,
character: 53
},
message: 'outdated import path'
}
]);

assertReplacements(err as RuleFailure[], source, after);
});
});
});

0 comments on commit 5c54550

Please sign in to comment.