From 9f2da415ea6510604cdf8aeb9bcbfe327a42f410 Mon Sep 17 00:00:00 2001 From: Wei Lu Date: Mon, 17 Mar 2014 16:13:49 +0800 Subject: [PATCH] fix script constructor array check --- src/script.js | 2 +- test/script.js | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/script.js b/src/script.js index 8c28012..7958d12 100644 --- a/src/script.js +++ b/src/script.js @@ -6,7 +6,7 @@ var network = require('./network'); var Script = function(data) { this.buffer = data || []; - if(!Array.isArray(data)) { + if(!Array.isArray(this.buffer)) { throw new Error('expect Script to be initialized with Array, but got ' + data) } this.parse(); diff --git a/test/script.js b/test/script.js index 2850fc7..08d747c 100644 --- a/test/script.js +++ b/test/script.js @@ -7,11 +7,12 @@ describe('Script', function() { assert.ok(new Script([])) }) + it('works when nothing is passed in', function() { + assert.ok(new Script()) + }) + it('throws an error when input is not an array', function() { - assert.throws(function(){ - new Script({}) - }) + assert.throws(function(){ new Script({}) }) }) }) - })