Reference:
Last active
August 29, 2015 14:02
-
-
Save dino-su/5a5190f888fa385ef61e to your computer and use it in GitHub Desktop.
node.js cycles modules
This file contains 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
var lib2 = require('./lib2'); | |
var lib3 = require('./lib3'); | |
var assert = require('assert'); | |
var lib1 = function() { | |
this.lib2Type = typeof(lib2); | |
this.lib3Type = typeof(lib3); | |
}; | |
module.exports = lib1; |
This file contains 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
var lib3 = require('./lib3.js'); | |
var assert = require('assert'); | |
var lib2 = function () { | |
var lib1 = require('./lib1.js'); | |
this.lib1Type = typeof(lib1); | |
this.lib3Type = typeof(lib3); | |
}; | |
module.exports = lib2; |
This file contains 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
var assert = require('assert'); | |
var lib3 = function() { | |
var lib1 = require('./lib1.js'); | |
this.lib1Type = typeof(lib1); | |
var lib2 = require('./lib2.js'); | |
this.lib2Type = typeof(lib2); | |
}; | |
module.exports = lib3; |
This file contains 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
var Lib1 = require('./lib1.js'); | |
var Lib2 = require('./lib2.js'); | |
var Lib3 = require('./lib3.js'); | |
var assert = require('assert'); | |
describe('Type of', function() { | |
'use strict'; | |
it('all should be function', function() { | |
assert.equal(typeof(Lib1), 'function'); | |
assert.equal(typeof(Lib2), 'function'); | |
assert.equal(typeof(Lib3), 'function'); | |
}); | |
it('all should still be function in lib1', function() { | |
var lib1 = new Lib1(); | |
assert.equal(lib1.lib2Type, 'function'); | |
assert.equal(lib1.lib3Type, 'function'); | |
}); | |
it('all should still be function in lib2', function() { | |
var lib2 = new Lib2(); | |
assert.equal(lib2.lib1Type, 'function'); // fail | |
assert.equal(lib2.lib3Type, 'function'); | |
}); | |
it('all should still be function in lib3', function() { | |
var lib3 = new Lib3(); | |
assert.equal(lib3.lib1Type, 'function'); // fail | |
assert.equal(lib3.lib2Type, 'function'); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment