Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

adding tests

  • Loading branch information...
commit 3d952f7e41f03261696cb698ef3a901047727178 1 parent a4fe3a6
@BryanDonovan authored
View
1  .gitignore
@@ -0,0 +1 @@
+node_modules
View
10 Makefile
@@ -0,0 +1,10 @@
+test:
+ ./node_modules/.bin/mocha
+
+test_with_mock:
+ ./node_modules/.bin/mocha test/with_mock.unit.js
+
+test_no_mock:
+ ./node_modules/.bin/mocha test/no_mock.unit.js
+
+.PHONY: test
View
0  index.js
No changes.
View
7 lib/foo.js
@@ -0,0 +1,7 @@
+var widget = require('./widget');
+
+var get_widget = function() {
+ return widget.get_widget();
+};
+
+exports.get_widget = get_widget;
View
5 lib/widget.js
@@ -0,0 +1,5 @@
+var get_widget = function() {
+ return 'real widget';
+};
+
+exports.get_widget = get_widget;
View
19 package.json
@@ -0,0 +1,19 @@
+{
+ "author": "Bryan Donovan <bdondo@gmail.com>",
+ "name": "nodejs-mock-test",
+ "description": "testing mocking with Mockery",
+ "version": "1.0.0",
+ "repository": {
+ "type": "git",
+ "url": "git://ithub.com:BryanDonovan/nodejs-mock-test.git"
+ },
+ "main": "index.js",
+ "engines": {
+ "node": ">=0.4.5"
+ },
+ "dependencies": {},
+ "devDependencies": {
+ "mockery": "1.0.0",
+ "mocha": "0.7.0"
+ }
+}
View
2  test/mocha.opts
@@ -0,0 +1,2 @@
+--reporter spec
+--ui bdd
View
10 test/no_mock.unit.js
@@ -0,0 +1,10 @@
+var assert = require('assert');
+var foo = require('../lib/foo');
+
+describe("no mock", function() {
+ it("returns real response", function(done) {
+ var result = foo.get_widget();
+ assert.equal(result, 'real widget');
+ done();
+ });
+});
View
30 test/with_mock.unit.js
@@ -0,0 +1,30 @@
+var assert = require('assert');
+var mockery = require('../../mockery');
+
+var mock_widget = {
+ get_widget: function() {
+ return 'mocked widget';
+ }
+};
+
+var foo;
+
+describe("with mock", function() {
+ before(function() {
+ mockery.enable();
+ mockery.registerMock('./widget', mock_widget);
+ mockery.registerAllowable('../lib/foo');
+ foo = require('../lib/foo');
+ });
+
+ after(function() {
+ mockery.disable();
+ mockery.deregisterAll();
+ });
+
+ it("returns mocked response", function(done) {
+ var result = foo.get_widget();
+ assert.equal(result, 'mocked widget');
+ done();
+ });
+});
Please sign in to comment.
Something went wrong with that request. Please try again.