I've google and SO'd extensively for the answer, and have a found a number of repositories and tutorials with something that wasn't quite what I was looking for, but I attempted to adapt anyway.
According to earlier issues I've looked through, the key to Blanket.js' coverage working is that window._$blanket is defined, and mine is, along with the instrumentations of my source.
However, when my testrunner.html loads, it tends to alternate between a full fledged blanket.js report, or the actual mocha tests (with checkmarks and css and whatnot). I'm inclined to think it has to do with the source being asynchronously loaded with RequireJS.
Here's my testRunner.html:
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="/js/vendor/npm/mocha/mocha.css" />
<script type="text/javascript" src="js/vendor/mocha/mocha.js"></script>
<script type="text/javascript" src="js/vendor/require.js"></script>
<script type="text/javascript" src="/js/test/unit/config.js"></script>
<script type="text/javascript" src="/js/main.js"></script>
</head>
<body>
<script type="text/javascript" data-cover-only="/js/test/unit/js/some/path/to/"
src="http://ift.tt/1Wnooca">
</script>
<script type="text/javascript" src="/js/vendor/blanket/src/adapters/mocha-blanket.js"></script>
<script>
require(['mocha', 'chai', 'chai-jquery', 'sinon'], function(mocha, chai, chaiJquery, sinon) {
// Init Chai
chai.should(); //initializes chai.should()
chai.use(chaiJquery);
expect = chai.expect;
mocha.setup({
ui: 'bdd',
ignoreLeaks: true
});
require([
'../js/test/unit/js/some/path/to/AModel.test.js',
'../js/test/unit/js/some/path/to/SModel.test.js',
], function(require) {
mocha.run();
});
});
</script>
<div id="mocha"></div>
</body>
</html>
and here's the somemodel.test.js file:
define([
"app",
"moment",
"util/utils",
],
function(app) {
describe('AModel', function() {
beforeEach(function () {
this.AModel = new AModel ({
type: undefined,
name: undefined,
});
sinon.stub(this.AModel, 'fetch').yieldsTo('success', {
fun: "funk"
});
});
afterEach(function () {
this.AModel = null;
});
it('should get a node returned from a given ID', function() {
var that = this;
var nodeModel = this.AModel.getNode("node1");
expect(nodeModel instanceof SModel).to.be.true;
});
it('should get the peer nodes of an object', function() {
var temp = this.AModel.getPeerNodes("node1", "fakeType" );
expect(temp).to.have.length(10);
});
});
}
);
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire