Skip to content

Commit

Permalink
add tests asserting array behavior
Browse files Browse the repository at this point in the history
* empty stub arrays are filled
* filled stub arrays are untouched
* you can set a non-enumerable @noCallThru via Object.defineProperty

This is not necessarily the ideal behavior, just the simplest way to
define where we are today and leave someone with the opporunity to
contribute a use case and a different strategy

Closes #191
  • Loading branch information
bendrucker committed Mar 1, 2018
1 parent 4bbad52 commit d20312e
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 0 deletions.
55 changes: 55 additions & 0 deletions test/proxyquire-non-object.js
Expand Up @@ -11,6 +11,8 @@ describe('Given foo requires the boof, foonum and foobool modules and boof is a
var boofber = 'a_string'
var foonumber = 4
var fooboolber = false
var emptyarray = []
var fooarray = ['x', 'y', 'z']

describe('When I resolve foo with boofber stub as boof.', function () {
before(function () {
Expand Down Expand Up @@ -62,4 +64,57 @@ describe('Given foo requires the boof, foonum and foobool modules and boof is a
})
})
})

describe('When I resolve foo with ./fooarray stub as fooarray.', function () {
before(function () {
stats.reset()
foo = proxyquire('./samples/foo', {'./fooarray': fooarray})
})

it('foo is required 1 times', function () {
assert.equal(stats.fooRequires(), 1)
})

describe('foo\'s fooarray is fooarray', function () {
it('foo.fooarray is fooarray', function () {
assert.deepEqual(foo.fooarray, ['x', 'y', 'z'])
})
})
})

describe('When I resolve foo with ./fooarray stub as empty.', function () {
before(function () {
stats.reset()
foo = proxyquire('./samples/foo', {'./fooarray': []})
})

it('foo is required 1 times', function () {
assert.equal(stats.fooRequires(), 1)
})

describe('foo\'s fooarray is the original', function () {
it('foo.fooarray is empty', function () {
assert.deepEqual(foo.fooarray, ['a', 'b', 'c'])
})
})
})

describe('When I resolve foo with ./fooarray stub as empty with @noCallThru.', function () {
before(function () {
stats.reset()
var empty = []
Object.defineProperty(empty, '@noCallThru', {value: true})
foo = proxyquire('./samples/foo', {'./fooarray': empty})
})

it('foo is required 1 times', function () {
assert.equal(stats.fooRequires(), 1)
})

describe('foo\'s fooarray is empty', function () {
it('foo.fooarray is empty', function () {
assert.deepEqual(foo.fooarray, [])
})
})
})
})
2 changes: 2 additions & 0 deletions test/samples/foo.js
Expand Up @@ -3,6 +3,7 @@ var bar = require('./bar')
var boof = require('./boof')
var foonum = require('./foonum')
var foobool = require('./foobool')
var fooarray = require('./fooarray')
var path = require('path')
var crypto

Expand Down Expand Up @@ -41,6 +42,7 @@ module.exports = {
boof: boof,
foonum: foonum,
foobool: foobool,
fooarray: fooarray,
bigCrypto: bigCrypto,
state: ''
}
1 change: 1 addition & 0 deletions test/samples/fooarray.js
@@ -0,0 +1 @@
module.exports = ['a', 'b', 'c']

0 comments on commit d20312e

Please sign in to comment.