-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test added for AstStages.Parser method
- Loading branch information
ozer
authored and
ozer
committed
Nov 3, 2018
1 parent
fdb2631
commit 0f4e672
Showing
6 changed files
with
257 additions
and
25 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,73 @@ | ||
const assert = require('assert') | ||
const expect = require('expect.js') | ||
var sinon = require('sinon') | ||
const AstStages = require('../lib/astStages').AstStages | ||
const stages = new AstStages() | ||
const fs = require('fs') | ||
|
||
|
||
suite("AST Stages", function() { | ||
suite("Parser", () => { | ||
/** | ||
* stages.parseToAst(file) | ||
* 1- test file parameter | ||
* 2- test parsedFile variable it should be equal to given ast | ||
* 3- returned value equal to parsedFile AST | ||
*/ | ||
let fn = sinon.spy(AstStages.prototype, 'parseToAst') | ||
const reactFilePath = './test/mockData/reactCodeMock.js' | ||
const returnedAST = require('./mockData/reactCodeASTMock').reactFileAST | ||
|
||
suite("given parameter to the parser is testing", () => { | ||
|
||
test("it should be defined", function() { | ||
expect(fn).to.be.a('function'); | ||
|
||
}); | ||
test("it should throw error if parameter is not string or Buffer", () => { | ||
expect(fn).withArgs(3).to.throwException(); | ||
}) | ||
|
||
test("it should throw error if no such a file", () => { | ||
expect(fn).withArgs('asdas').to.throwException(); | ||
}) | ||
|
||
test("it should be a valid file path", () => { | ||
expect(fn).withArgs(reactFilePath).to.not.throwException(); | ||
}) | ||
|
||
test("it should be a JavaScript file", () => { | ||
expect(reactFilePath).to.contain('.js'); | ||
}) | ||
|
||
test("returned value should be an Object", () => { | ||
expect(fn).withArgs(reactFilePath).to.not.throwException(); | ||
}) | ||
}) | ||
|
||
suite("returned AST Object is testing", () => { | ||
|
||
test("it should be an object", () => { | ||
expect(fn(reactFilePath)).to.be.an('object'); | ||
}) | ||
|
||
test("it should not be an empy object", () => { | ||
expect(fn(reactFilePath)).to.not.be.empty(); | ||
}) | ||
|
||
test("it should be have property named PROGRAM", () => { | ||
expect(fn(reactFilePath)).to.have.property('program'); | ||
}) | ||
|
||
test("it shouldn't be an empty AST", () => { | ||
expect(fn(reactFilePath)).to.not.be.empty() | ||
}) | ||
|
||
test("it should be a valid AST", () => { | ||
assert.deepEqual(fn(reactFilePath), returnedAST) | ||
}) | ||
|
||
}) | ||
}) | ||
|
||
}); |
This file was deleted.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
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,30 @@ | ||
class NameForm extends React.Component { | ||
constructor(props) { | ||
super(props); | ||
this.state = {value: ''}; | ||
|
||
this.handleChange = this.handleChange.bind(this); | ||
this.handleSubmit = this.handleSubmit.bind(this); | ||
} | ||
|
||
handleChange(event) { | ||
this.setState({value: event.target.value}); | ||
} | ||
|
||
handleSubmit(event) { | ||
alert('A name was submitted: ' + this.state.value); | ||
event.preventDefault(); | ||
} | ||
|
||
render() { | ||
return ( | ||
<form onSubmit={this.handleSubmit}> | ||
<label> | ||
Name: | ||
<input type="text" value={this.state.value} onChange={this.handleChange} /> | ||
</label> | ||
<input type="submit" value="Submit" /> | ||
</form> | ||
); | ||
} | ||
} |