forked from dollarshaveclub/es-check
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #225 from yowainwright/init-add-more-tests
Init add more tests
- Loading branch information
Showing
3 changed files
with
136 additions
and
4 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,129 @@ | ||
// test/checkFunctions.spec.js | ||
|
||
const assert = require('assert'); | ||
const { | ||
checkVarKindMatch, | ||
checkCalleeMatch, | ||
checkOperatorMatch, | ||
checkDefault, | ||
checkMap, | ||
} = require('./utils'); | ||
|
||
describe('Check Functions', function () { | ||
describe('checkVarKindMatch', function () { | ||
it('should return false if astInfo.kind is not provided', function () { | ||
const node = { kind: 'const' }; | ||
const astInfo = {}; // no "kind" | ||
assert.strictEqual(checkVarKindMatch(node, astInfo), false); | ||
}); | ||
|
||
it('should return true if node.kind equals astInfo.kind', function () { | ||
const node = { kind: 'const' }; | ||
const astInfo = { kind: 'const' }; | ||
assert.strictEqual(checkVarKindMatch(node, astInfo), true); | ||
}); | ||
|
||
it('should return false if node.kind does not match astInfo.kind', function () { | ||
const node = { kind: 'let' }; | ||
const astInfo = { kind: 'const' }; | ||
assert.strictEqual(checkVarKindMatch(node, astInfo), false); | ||
}); | ||
}); | ||
|
||
describe('checkCalleeMatch', function () { | ||
it('should return false if astInfo.callee is not provided', function () { | ||
const node = { | ||
callee: { type: 'Identifier', name: 'Promise' }, | ||
}; | ||
const astInfo = {}; // no "callee" | ||
assert.strictEqual(checkCalleeMatch(node, astInfo), false); | ||
}); | ||
|
||
it('should return false if node.callee is missing', function () { | ||
const node = {}; | ||
const astInfo = { callee: 'Promise' }; | ||
assert.strictEqual(checkCalleeMatch(node, astInfo), false); | ||
}); | ||
|
||
it('should return false if node.callee.type !== "Identifier"', function () { | ||
const node = { | ||
callee: { type: 'MemberExpression', name: 'Promise' }, | ||
}; | ||
const astInfo = { callee: 'Promise' }; | ||
assert.strictEqual(checkCalleeMatch(node, astInfo), false); | ||
}); | ||
|
||
it('should return false if the callee name does not match astInfo.callee', function () { | ||
const node = { | ||
callee: { type: 'Identifier', name: 'WeakRef' }, | ||
}; | ||
const astInfo = { callee: 'Promise' }; | ||
assert.strictEqual(checkCalleeMatch(node, astInfo), false); | ||
}); | ||
|
||
it('should return true if callee name matches astInfo.callee', function () { | ||
const node = { | ||
callee: { type: 'Identifier', name: 'Promise' }, | ||
}; | ||
const astInfo = { callee: 'Promise' }; | ||
assert.strictEqual(checkCalleeMatch(node, astInfo), true); | ||
}); | ||
}); | ||
|
||
describe('checkOperatorMatch', function () { | ||
it('should return false if astInfo.operator is not provided', function () { | ||
const node = { operator: '??' }; | ||
const astInfo = {}; // no "operator" | ||
assert.strictEqual(checkOperatorMatch(node, astInfo), false); | ||
}); | ||
|
||
it('should return false if node.operator does not match astInfo.operator', function () { | ||
const node = { operator: '**' }; | ||
const astInfo = { operator: '??' }; | ||
assert.strictEqual(checkOperatorMatch(node, astInfo), false); | ||
}); | ||
|
||
it('should return true if node.operator matches astInfo.operator', function () { | ||
const node = { operator: '??' }; | ||
const astInfo = { operator: '??' }; | ||
assert.strictEqual(checkOperatorMatch(node, astInfo), true); | ||
}); | ||
}); | ||
|
||
describe('checkDefault', function () { | ||
it('should always return true', function () { | ||
assert.strictEqual(checkDefault(), true); | ||
}); | ||
}); | ||
|
||
describe('checkMap usage examples', function () { | ||
it('checkMap.VariableDeclaration should call checkVarKindMatch internally and return correct boolean', function () { | ||
const node = { kind: 'const' }; | ||
const astInfo = { kind: 'const' }; | ||
const result = checkMap.VariableDeclaration(node, astInfo); | ||
assert.strictEqual(result, true); | ||
|
||
const nodeMismatch = { kind: 'let' }; | ||
const result2 = checkMap.VariableDeclaration(nodeMismatch, astInfo); | ||
assert.strictEqual(result2, false); | ||
}); | ||
|
||
it('checkMap.LogicalExpression should call checkOperatorMatch internally', function () { | ||
const node = { operator: '??' }; | ||
const astInfo = { operator: '??' }; | ||
const result = checkMap.LogicalExpression(node, astInfo); | ||
assert.strictEqual(result, true); | ||
}); | ||
|
||
it('checkMap.ArrowFunctionExpression should call checkDefault internally', function () { | ||
const result = checkMap.ArrowFunctionExpression(); | ||
assert.strictEqual(result, true); | ||
}); | ||
|
||
it('checkMap.default should return false if node type is unsupported', function () { | ||
const result = checkMap.default(); | ||
assert.strictEqual(result, false); | ||
}); | ||
}); | ||
|
||
}); |