-
Notifications
You must be signed in to change notification settings - Fork 11
Add unit tests #6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,2 +1,3 @@ | ||
npm-debug.log | ||
node_modules | ||
coverage |
This file contains hidden or 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,8 @@ | ||
language: node_js | ||
node_js: | ||
- "6" | ||
- "5" | ||
- "4" | ||
script: | ||
- npm run lint | ||
- npm run test-coveralls |
This file contains hidden or 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 hidden or 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 hidden or 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,39 @@ | ||
var chai = require('chai'); | ||
var expect = chai.expect; | ||
var React = require('../index'); | ||
|
||
describe('React', function () { | ||
describe('cleanHtml', function () { | ||
it('should be a function', function () { | ||
expect(React.cleanHtml).to.be.a('function'); | ||
}); | ||
|
||
it('should clean rendered string', function () { | ||
expect(React.cleanHtml('<!----><a>link</a>')).to.equal('<a>link</a>'); | ||
}); | ||
}); | ||
|
||
describe('createClass', function () { | ||
it('should be a function', function () { | ||
expect(React.createClass).to.be.a('function'); | ||
}); | ||
|
||
it('should return a function', function () { | ||
expect(React.createClass({})).to.be.a('function'); | ||
}); | ||
}); | ||
|
||
describe('createElement', function () { | ||
it('should be a function', function () { | ||
expect(React.createElement).to.be.a('function'); | ||
}); | ||
|
||
it('should render div as string', function () { | ||
expect(React.createElement('div')).to.equal('<!----><div></div>'); | ||
}); | ||
|
||
it('should render null object', function () { | ||
expect(React.createElement(null)).to.equal(''); | ||
}); | ||
}); | ||
}); |
This file contains hidden or 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,34 @@ | ||
var chai = require('chai'); | ||
var expect = chai.expect; | ||
var dasherize = require('../../utils/dasherize'); | ||
|
||
describe('dasherize', function () { | ||
it('should be a function', function () { | ||
expect(dasherize).to.be.a('function'); | ||
}); | ||
|
||
it('should change UpperCamelCase to kebab-case', function () { | ||
expect(dasherize('UpperCamelCase')).to.equal('upper-camel-case'); | ||
}); | ||
|
||
it('should change lowerCamelCase to kebab-case', function () { | ||
expect(dasherize('lowerCamelCase')).to.equal('lower-camel-case'); | ||
}); | ||
|
||
it('should not change lowercase string', function () { | ||
var string = 'lowercase string'; | ||
expect(dasherize(string)).to.equal(string); | ||
}); | ||
|
||
it('should return `background` css properties', function () { | ||
expect(dasherize('background')).to.equal('background'); | ||
}); | ||
|
||
it('should return `z-index` css properties', function () { | ||
expect(dasherize('zIndex')).to.equal('z-index'); | ||
}); | ||
|
||
it('should return `border-bottom-color` css properties', function () { | ||
expect(dasherize('borderBottomColor')).to.equal('border-bottom-color'); | ||
}); | ||
}); |
This file contains hidden or 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,22 @@ | ||
var chai = require('chai'); | ||
var expect = chai.expect; | ||
var attr = require('../../../utils/escape/attr'); | ||
|
||
describe('attr', function () { | ||
it('should be a function', function () { | ||
expect(attr).to.be.a('function'); | ||
}); | ||
|
||
it('should not change correct string', function () { | ||
var string = 'forbidden'; | ||
expect(attr(string)).to.equal(string); | ||
}); | ||
|
||
it('should escape `&` sign', function () { | ||
expect(attr('&')).to.equal('&'); | ||
}); | ||
|
||
it('should escape `"` sign', function () { | ||
expect(attr('"')).to.equal('"'); | ||
}); | ||
}); |
This file contains hidden or 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 @@ | ||
var chai = require('chai'); | ||
var expect = chai.expect; | ||
var html = require('../../../utils/escape/html'); | ||
|
||
describe('html', function () { | ||
it('should be a function', function () { | ||
expect(html).to.be.a('function'); | ||
}); | ||
|
||
it('should not change correct string', function () { | ||
var string = 'div a="b"'; | ||
expect(html(string)).to.equal(string); | ||
}); | ||
|
||
it('should escape `&` sign', function () { | ||
expect(html('&')).to.equal('&'); | ||
}); | ||
|
||
it('should escape `<` sign', function () { | ||
expect(html('<')).to.equal('<'); | ||
}); | ||
|
||
it('should escape `>` sign', function () { | ||
expect(html('>')).to.equal('>'); | ||
}); | ||
|
||
it('should escape html string', function () { | ||
expect(html('<div class="name">></div>')).to.equal('<div class="name">&gt;</div>'); | ||
}); | ||
}); |
This file contains hidden or 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,87 @@ | ||
var chai = require('chai'); | ||
var expect = chai.expect; | ||
var extend = require('../../utils/extend'); | ||
|
||
var str = 'me a test'; | ||
var integer = 10; | ||
var arr = [1, 'what', new Date(81, 8, 4)]; | ||
var date = new Date(81, 4, 13); | ||
|
||
var Foo = function () {}; | ||
|
||
var obj = { | ||
str: str, | ||
integer: integer, | ||
arr: arr, | ||
date: date, | ||
constructor: 'fake', | ||
isPrototypeOf: 'not a function', | ||
foo: new Foo() | ||
}; | ||
|
||
describe('extend', function () { | ||
it('should be a function', function () { | ||
expect(extend).to.be.a('function'); | ||
}); | ||
|
||
it('without arguments should return an object', function () { | ||
expect(extend()).to.deep.equal({}); | ||
}); | ||
|
||
it('should merge object with object', function () { | ||
var ori = { | ||
str: 'no shit', | ||
integer: 76, | ||
arr: [1, 2, 3, 4], | ||
date: new Date(81, 7, 26), | ||
foo: 'bar' | ||
}; | ||
var target = extend(ori, obj); | ||
var expectedObj = { | ||
str: 'me a test', | ||
integer: 10, | ||
arr: [1, 'what', new Date(81, 8, 4)], | ||
date: new Date(81, 4, 13), | ||
constructor: 'fake', | ||
isPrototypeOf: 'not a function', | ||
foo: new Foo() | ||
}; | ||
var expectedTarget = { | ||
str: 'me a test', | ||
integer: 10, | ||
arr: [1, 'what', new Date(81, 8, 4)], | ||
date: new Date(81, 4, 13), | ||
constructor: 'fake', | ||
isPrototypeOf: 'not a function', | ||
foo: new Foo() | ||
}; | ||
expect(obj).to.deep.equal(expectedObj); | ||
expect(target).to.deep.equal(expectedTarget); | ||
}); | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we can add test for case one and three object |
||
it('should handle null object normally', function () { | ||
var target = extend(null, obj); | ||
expect(target).to.deep.equal(obj); | ||
}); | ||
|
||
it('should merge any count of objects', function () { | ||
var ori = { | ||
str: 'no shit', | ||
integer: 76, | ||
arr: [1, 2, 3, 4], | ||
date: new Date(81, 7, 26), | ||
foo: 'bar' | ||
}; | ||
var target = extend(ori, obj, {str: 'normal', integer: 0}, {integer: 42}); | ||
var expectedTarget = { | ||
str: 'normal', | ||
integer: 42, | ||
arr: [1, 'what', new Date(81, 8, 4)], | ||
date: new Date(81, 4, 13), | ||
constructor: 'fake', | ||
isPrototypeOf: 'not a function', | ||
foo: new Foo() | ||
}; | ||
expect(target).to.deep.equal(expectedTarget); | ||
}); | ||
}); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in the coming days, lib API will change (#5), so you can cover only utils
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, I left only the primary tests