-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
7 additions
and
12 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,13 @@ | ||
import genericPrint from '../../src/printer.js'; | ||
|
||
test('given an unknown operator then the BinaryOperation print function should throw', () => { | ||
const mockPath = { | ||
getNode: () => ({ type: 'BinaryOperation', operator: '?' }) | ||
}; | ||
const node = mockPath.getNode(); | ||
const mockPath = { node: { type: 'BinaryOperation', operator: '?' } }; | ||
|
||
expect(() => { | ||
genericPrint(mockPath); | ||
}).toThrow( | ||
`Assertion error: no printer found for operator ${JSON.stringify( | ||
node.operator | ||
mockPath.node.operator | ||
)}` | ||
); | ||
}); |
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 |
---|---|---|
@@ -1,18 +1,17 @@ | ||
import genericPrint from '../../src/printer.js'; | ||
|
||
test('given an unknown module type then genericPrint function should throw', () => { | ||
const mockPath = { getNode: () => ({ type: 'UnknownModule' }) }; | ||
const node = mockPath.getNode(); | ||
const mockPath = { node: { type: 'UnknownModule' } }; | ||
|
||
expect(() => { | ||
genericPrint(mockPath); | ||
}).toThrow(`Unknown type: ${JSON.stringify(node.type)}`); | ||
}).toThrow(`Unknown type: ${JSON.stringify(mockPath.node.type)}`); | ||
}); | ||
|
||
test('if the AST contains a null node, print an empty string', () => { | ||
// Prettier V3 avoids returning null when traversing the AST, but V2 does not. | ||
// By mocking this, we ensure both cases are covered. | ||
const mockPath = { getNode: () => null }; | ||
const mockPath = { node: null }; | ||
|
||
expect(genericPrint(mockPath)).toEqual(''); | ||
}); |