Skip to content

Commit

Permalink
Initial commit.
Browse files Browse the repository at this point in the history
  • Loading branch information
percyhanna committed Jul 8, 2014
0 parents commit 219c8f7
Show file tree
Hide file tree
Showing 9 changed files with 196 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.settings.xml
node_modules/
bower_components/
.DS_Store
*.swp
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
language: node_js
22 changes: 22 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
Copyright (c) 2014 Andrew Hanna

MIT License

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# chai-react

chai-react is an extension to the [chai](http://chaijs.com/) assertion library that
provides a set of React-specific assertions.

## Contributing

To run the test suite, run `npm install` (requires
[Node.js](http://nodejs.org/) to be installed on your system), and open
`test/index.html` in your web browser.

## License

Copyright (c) 2014 Andrew Hanna

MIT License (see the LICENSE file)

## Credits

Thanks to [John Firebaugh](https://github.com/jfirebaugh) for providing
[chai-jquery](https://github.com/chaijs/chai-jquery/), which served as a
foundation for this plugin.
31 changes: 31 additions & 0 deletions bower.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"name": "chai-react",
"main": "chai-react.js",
"version": "0.0.1",
"authors": [
"Andrew Hanna <[email protected]>"
],
"description": "React assertions for Chai.",
"moduleType": [
"amd",
"node"
],
"keywords": [
"chai",
"react",
"testing",
"assertion"
],
"license": "MIT",
"private": true,
"ignore": [
"**/.*",
"node_modules",
"bower_components",
"test",
"tests"
],
"dependencies": {
"react": "~0.10.0"
}
}
56 changes: 56 additions & 0 deletions chai-react.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
(function (chaiReact) {
// Module systems magic dance.
if (typeof require === "function" && typeof exports === "object" && typeof module === "object") {
// NodeJS
module.exports = chaiReact;
} else if (typeof define === "function" && define.amd) {
// AMD
define(['react'], function (React) {
return function (chai, utils) {
return chaiReact(chai, utils, React);
};
});
} else {
// Other environment (usually <script> tag): plug in to global chai instance directly.
chai.use(function (chai, utils) {
return chaiReact(chai, utils, React);
});
}
}(function (chai, utils, React) {
var inspect = utils.inspect,
flag = utils.flag;

window.chaiReact = React;

var div = document.createElement('div'),
sampleClass = React.createClass({
render: function () {
return React.DOM.div();
}
}),
sampleComponent = React.renderComponent(sampleClass(), div);

chai.Assertion.addMethod('state', function (name, value) {
var component = flag(this, 'object'),
state = component.state,
actual = state[name];

if (!flag(this, 'negate') || undefined === value) {
this.assert(
undefined !== actual,
'expected #{this} to have state.' + name + ' #{exp}',
'expected #{this} not to have state.' + name + ' #{exp}'
);
}

if (undefined !== value) {
this.assert(
value === actual,
'expected #{this} to have state.' + name + ' with the value #{exp}, but the value was #{act}',
'expected #{this} not to have state.' + name + ' with the value #{act}'
);
}

flag(this, 'object', actual);
});
}));
32 changes: 32 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"author": "Andrew Hanna <[email protected]>",
"name": "chai-react",
"description": "React assertions for the Chai assertion library",
"keywords": [
"test",
"assertion",
"assert",
"testing",
"react"
],
"version": "0.0.1",
"repository": {
"type": "git",
"url": "https://github.com/percyhanna/chai-react"
},
"bugs": {
"url": "https://github.com/percyhanna/chai-react/issues"
},
"scripts": {
"test": "mocha-phantomjs test/index.html"
},
"main": "./chai-react",
"engines": {
"node": ">= 0.4.0"
},
"devDependencies": {
"chai": "1",
"mocha": "1",
"mocha-phantomjs": "3"
}
}
4 changes: 4 additions & 0 deletions test/chai-react-spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
describe("React assertions", function() {
chai.use(function (chai, utils) {
});
});
23 changes: 23 additions & 0 deletions test/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<html>
<head>
<title>Mocha</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="../node_modules/mocha/mocha.css" />
<script src="../bower_components/react/react.js"></script>
<script src="../node_modules/mocha/mocha.js"></script>
<script src="../node_modules/chai/chai.js"></script>
<script src="../chai-jquery.js"></script>
<script>
mocha.setup('bdd');
var should = chai.should();
window.onload = function () {
(window.mochaPhantomJS || window.mocha).run();
};
</script>
<script src="jquery-inspect-spec.js"></script>
<script src="chai-jquery-spec.js"></script>
</head>
<body>
<div id="mocha"></div>
</body>
</html>

0 comments on commit 219c8f7

Please sign in to comment.