Skip to content

Commit 1456fc8

Browse files
author
Lukas Oppermann
committed
Merge pull request #109 from lukasoppermann/mocha
adding more tests
2 parents eab3ba1 + b44bc3f commit 1456fc8

File tree

7 files changed

+77
-14
lines changed

7 files changed

+77
-14
lines changed

gulpfile.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ gulp.task('umd', function() {
4848
name: '$',
4949
amd: 'jquery',
5050
cjs: 'jquery',
51-
global: 'jquery'
51+
global: 'jQuery'
5252
}];
5353
},
5454
exports: function() {

package.json

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
"email": "[email protected]"
3232
},
3333
"devDependencies": {
34+
"chai": "^2.3.0",
3435
"del": "^1.1.1",
3536
"gulp": "^3.8.11",
3637
"gulp-bump": "^0.3.0",
@@ -41,12 +42,19 @@
4142
"gulp-uglify": "^1.2.0",
4243
"gulp-umd": "^0.1.3",
4344
"gulp-util": "^3.0.4",
45+
"jsdom": "^3.x",
4446
"jshint-stylish": "^1.0.1",
47+
"mocha": "^2.2.4",
48+
"mocha-phantomjs": "^3.5.3",
4549
"mochify": "^2.8.1",
46-
"phantomjs": "^1.9.16"
50+
"phantomjs": "^1.9.16",
51+
"requirejs": "^2.1.17"
4752
},
4853
"scripts": {
49-
"test": "node_modules/.bin/mochify --phantomjs node_modules/.bin/phantomjs && gulp test",
54+
"test": "npm run test-mocha && npm run test-phantom && npm run test-require && gulp test",
55+
"test-mocha": "./node_modules/.bin/mocha test/api.js test/angular.js",
56+
"test-require": "./node_modules/.bin/mochify --phantomjs ./node_modules/.bin/phantomjs ./test/test_browserify.js -R spec",
57+
"test-phantom": "./node_modules/.bin/mocha-phantomjs -p ./node_modules/.bin/phantomjs ./test/html/*.html",
5058
"build": "gulp build"
5159
},
5260
"dependencies": {

test/amd.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
require.config({
2+
baseUrl: "./",
3+
paths: {
4+
"jquery": "../../node_modules/jquery/dist/jquery"
5+
}
6+
});
7+
require(["../../dist/html.sortable.js"], function(sortable) {
8+
// test specific use cases
9+
describe("AMD", function () {
10+
it("should require jQuery", function () {
11+
assert.typeOf($,"function");
12+
});
13+
14+
it("should define sortable", function () {
15+
assert.typeOf(sortable,"function");
16+
});
17+
18+
it("should define $().sortable", function () {
19+
assert.typeOf($().sortable,"function");
20+
});
21+
22+
});
23+
24+
if (window.mochaPhantomJS) { mochaPhantomJS.run(); }
25+
else { mocha.run(); }
26+
});

test/api.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,16 @@
11
// testing basic api
2+
var assert = require("chai").assert;
3+
var sortable;
4+
5+
describe('Basics', function(){
6+
before(function(){
7+
GLOBAL.document = require("jsdom").jsdom('<html lang="en-US"></html>');
8+
GLOBAL.window = document.defaultView;
9+
sortable = require("../dist/html.sortable.js");
10+
});
11+
12+
it('sortable should be a function', function(){
13+
assert.typeOf(sortable,"function");
14+
});
15+
16+
})

test/html/amd.html

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
2+
<html>
3+
<body>
4+
<div id="mocha"></div>
5+
<link rel="stylesheet" href="../../node_modules/mocha/mocha.css" />
6+
<script src="../../node_modules/mocha/mocha.js"></script>
7+
<script src="../../node_modules/chai/chai.js"></script>
8+
<script>
9+
mocha.ui('bdd');
10+
mocha.reporter('html');
11+
var assert = chai.assert;
12+
</script>
13+
<script data-main="../amd.js" src="../../node_modules/requirejs/require.js"></script>
14+
</body>
15+
</html>

test/integration.js

Lines changed: 0 additions & 1 deletion
This file was deleted.

test/test_browserify.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
assert = require('assert');
22

33
describe('Browserify', function(){
4-
it('should be able to require jquery', function() {
5-
require('jquery');
6-
});
7-
it('should be able to require html.sortable', function() {
8-
require('../dist/html.sortable.js');
9-
});
10-
it('should find the exported function on a jQuery object', function() {
11-
var $ = require('jquery');
12-
assert.equal((typeof $().sortable), 'function');
13-
});
4+
it('should be able to require jquery', function() {
5+
require('jquery');
6+
});
7+
it('should be able to require html.sortable', function() {
8+
require('../dist/html.sortable.js');
9+
});
10+
it('should find the exported function on a jQuery object', function() {
11+
var $ = require('jquery');
12+
assert.equal((typeof $().sortable), 'function');
13+
});
1414
});

0 commit comments

Comments
 (0)