-
Notifications
You must be signed in to change notification settings - Fork 250
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(BlockStatementMutator): Not mutate empty block (#160)
- Loading branch information
Showing
4 changed files
with
43 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import BlockStatementMutator from '../../../src/mutators/BlockStatementMutator'; | ||
import { expect } from 'chai'; | ||
import * as parser from '../../../src/utils/parserUtils'; | ||
import { copy } from '../../../src/utils/objectUtils'; | ||
import { Syntax } from 'esprima'; | ||
import * as estree from 'estree'; | ||
|
||
describe('BlockStatementMutator', () => { | ||
let sut: BlockStatementMutator; | ||
|
||
beforeEach(() => sut = new BlockStatementMutator()); | ||
|
||
it('should mutate when supplied a block statement', () => { | ||
// Arrange | ||
const program = parser.parse(`function a () { | ||
'use strict'; | ||
}`); | ||
const useStrictBlockStatement = (program.body[0] as estree.FunctionDeclaration).body; | ||
|
||
// Act | ||
const actual = <estree.BlockStatement>sut.applyMutations(useStrictBlockStatement, copy); | ||
|
||
// Assert | ||
expect(actual).to.be.ok; | ||
expect(actual.nodeID).to.eq(useStrictBlockStatement.nodeID); | ||
expect(actual.body).to.have.length(0); | ||
}); | ||
|
||
it('should not mutate an empty expression', () => { | ||
// Arrange | ||
const program = parser.parse(`function a () { | ||
}`); | ||
const emptyBlockStatement = (program.body[0] as estree.FunctionDeclaration).body; | ||
|
||
// Act | ||
const actual = sut.applyMutations(emptyBlockStatement, copy); | ||
expect(actual).to.not.be.ok; | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters