Skip to content

Commit

Permalink
test: remove "should" usage
Browse files Browse the repository at this point in the history
Just use the built-in "assert" module instead.
  • Loading branch information
TooTallNate committed Nov 10, 2013
1 parent 2e30730 commit 60c78a9
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 38 deletions.
3 changes: 1 addition & 2 deletions package.json
Expand Up @@ -30,7 +30,6 @@
"bindings": "*" "bindings": "*"
}, },
"devDependencies": { "devDependencies": {
"mocha": "> 0.7.0", "mocha": "> 0.7.0"
"should": "*"
} }
} }
8 changes: 4 additions & 4 deletions test/buffer.js
@@ -1,4 +1,4 @@
require('should') var assert = require('assert')
var weak = require('../') var weak = require('../')


describe('weak()', function () { describe('weak()', function () {
Expand All @@ -12,12 +12,12 @@ describe('weak()', function () {
var called = false var called = false
weak(Buffer('test'), function (buf) { weak(Buffer('test'), function (buf) {
called = true called = true
buf.toString().should.equal('test') assert.equal('test', buf.toString())
}) })


called.should.be.false assert(!called)
gc() gc()
called.should.be.true assert(called)
}) })


}) })
Expand Down
18 changes: 9 additions & 9 deletions test/callback.js
@@ -1,4 +1,4 @@
require('should') var assert = require('assert')
var weak = require('../') var weak = require('../')


describe('weak()', function () { describe('weak()', function () {
Expand All @@ -9,22 +9,22 @@ describe('weak()', function () {


it('should accept a function as second argument', function () { it('should accept a function as second argument', function () {
var r = weak({}, function () {}) var r = weak({}, function () {})
weak.callbacks(r).should.have.lengthOf(1) assert.equal(1, weak.callbacks(r).length)
}) })


it('should invoke the callback before the target is gc\'d', function () { it('should invoke the callback before the target is gc\'d', function () {
var called = false var called = false
weak({}, function () { weak({}, function () {
called = true called = true
}) })
called.should.equal.false assert(!called)
gc() gc()
called.should.equal.true assert(called)
}) })


it('should pass the target in as the first argument', function () { it('should pass the target in as the first argument', function () {
weak({ foo: 'bar' }, function (o) { weak({ foo: 'bar' }, function (o) {
o.should.have.property('foo', 'bar') assert.equal(o.foo, 'bar')
}) })
gc() gc()
}) })
Expand All @@ -41,8 +41,8 @@ describe('weak()', function () {
called2 = true called2 = true
}) })
gc() gc()
called1.should.equal.true assert(called1)
called2.should.equal.true assert(called2)
}) })


}) })
Expand All @@ -53,8 +53,8 @@ describe('callbacks()', function () {
it('should return the Weakref\'s internal "callback" Array', function () { it('should return the Weakref\'s internal "callback" Array', function () {
var r = weak({}) var r = weak({})
, callbacks = weak.callbacks(r) , callbacks = weak.callbacks(r)
callbacks.should.be.instanceof(Array) assert(Array.isArray(callbacks))
callbacks.should.have.lengthOf(0) assert.equal(0, callbacks.length)
}) })


}) })
6 changes: 3 additions & 3 deletions test/create.js
@@ -1,5 +1,5 @@
var should = require('should') var assert = require('assert')
, weak = require('../') var weak = require('../')


describe('create()', function () { describe('create()', function () {


Expand All @@ -14,7 +14,7 @@ describe('create()', function () {
, undefined , undefined
, 'foo' , 'foo'
].forEach(function (val) { ].forEach(function (val) {
should.throws(function () { assert.throws(function () {
weak.create(val) weak.create(val)
}) })
}) })
Expand Down
40 changes: 20 additions & 20 deletions test/weakref.js
@@ -1,4 +1,4 @@
require('should') var assert = require('assert')
var weak = require('../') var weak = require('../')


describe('Weakref', function () { describe('Weakref', function () {
Expand All @@ -7,73 +7,73 @@ describe('Weakref', function () {


it('weak() should return a `Weakref` instance', function () { it('weak() should return a `Weakref` instance', function () {
var ref = weak({}) var ref = weak({})
weak.isWeakRef(ref).should.be.true assert(weak.isWeakRef(ref))
}) })


it('should proxy named gets to the target', function () { it('should proxy named gets to the target', function () {
var o = { foo: 'bar' } var o = { foo: 'bar' }
, r = weak(o) , r = weak(o)
r.should.have.property('foo', 'bar') assert.equal(r.foo, 'bar')
}) })


it('should proxy named sets to the target', function () { it('should proxy named sets to the target', function () {
var o = {} var o = {}
, r = weak(o) , r = weak(o)
r.foo = 'bar' r.foo = 'bar'
o.should.have.property('foo', 'bar') assert.equal(r.foo, 'bar')
}) })


it('should proxy named deletes to the target', function () { it('should proxy named deletes to the target', function () {
var o = { foo: 'bar' } var o = { foo: 'bar' }
, r = weak(o) , r = weak(o)
delete r.foo delete r.foo
o.should.not.have.property('foo') console.error(Object.getOwnPropertyNames(r));
assert(!('foo' in r))
}) })


it('should proxy indexed gets to the target', function () { it('should proxy indexed gets to the target', function () {
var a = [ 'foo' ] var a = [ 'foo' ]
, r = weak(a) , r = weak(a)
a.should.have.lengthOf(1) assert.equal(1, a.length)
r.should.have.lengthOf(1) assert.equal(1, r.length)
r[0].should.equal('foo') assert.equal('foo', r[0])
}) })


it('should proxy indexed sets to the target', function () { it('should proxy indexed sets to the target', function () {
var a = [] var a = []
, r = weak(a) , r = weak(a)
a.should.have.lengthOf(0) assert.equal(0, a.length)
r.should.have.lengthOf(0) assert.equal(0, r.length)
r[0] = 'foo' r[0] = 'foo'
a.should.have.lengthOf(1) assert.equal(1, a.length)
a[0].should.equal('foo') assert.equal('foo', a[0])
r.push('bar') r.push('bar')
a.should.have.lengthOf(2) assert.equal(2, a.length)
a[1].should.equal('bar') assert.equal('bar', a[1])
}) })


it('should proxy indexed deletes to the target', function () { it('should proxy indexed deletes to the target', function () {
var a = [ 'foo' ] var a = [ 'foo' ]
, r = weak(a) , r = weak(a)
delete r[0] delete r[0]
var t = typeof a[0] assert.equal('undefined', typeof a[0])
t.should.equal('undefined')
}) })


it('should proxy enumeration', function () { it('should proxy enumeration', function () {
var o = { a: 'a', b: 'b', c: 'c', d: 'd' } var o = { a: 'a', b: 'b', c: 'c', d: 'd' }
, r = weak(o) , r = weak(o)
r.should.have.keys(Object.keys(o)) assert.deepEquals(Object.keys(o), Object.keys(r))
}) })


it('should act like an empty object after target is gc\'d' it('should act like an empty object after target is gc\'d'
, function () { , function () {
var o = { foo: 'bar' } var o = { foo: 'bar' }
, r = weak(o) , r = weak(o)
o = null o = null
r.should.have.property('foo', 'bar') assert.equal('bar', r.foo)
gc() gc()
r.should.not.have.property('foo') assert(!('foo' in r))
Object.keys(r).should.have.lengthOf(0) assert.equal(0,Object.keys(r).length)
}) })


}) })

0 comments on commit 60c78a9

Please sign in to comment.