Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Assert in new context #706

Closed
wants to merge 2 commits into from

6 participants

@lukebayes

This is patch that helps make assert.throws work properly within new contexts.

#693

@lukebayes

Just checking in here to see if you'll be able to pull this, or if I should provide some other updates?

Thanks,

Luke

@ELLIOTTCABLE

Any particular reason this hasn’t been pulled yet? I am in need of this functionality too.

@trevnorris
Owner

This pull request now has a few conflicts in test/simple/test-script-context.js. Will need to be resolved.

@bnoordhuis
Owner

I don't mind landing this but it needs to be rebased against master.

@trevnorris trevnorris referenced this pull request
Closed

Assert in new context #4370

@trevnorris
Owner

@bnoordhuis I've taken the branch and rebased it against master in #4370.

@Nodejs-Jenkins

Can one of the admins verify this patch?

@hackedy

Hey, this can be closed. It got moved over to #4370 and closed there. /cc @isaacs @bnoordhuis

@bnoordhuis bnoordhuis closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Feb 20, 2011
  1. @lukebayes
Commits on Mar 4, 2011
  1. @lukebayes

    Updated expectation to check for RegExp in a more compliant and confi…

    lukebayes authored
    …dent manner, based on feedback from tobie
This page is out of date. Refresh to see the latest.
Showing with 9 additions and 3 deletions.
  1. +1 −1  lib/assert.js
  2. +8 −2 test/simple/test-script-context.js
View
2  lib/assert.js
@@ -245,7 +245,7 @@ function expectedException(actual, expected) {
return false;
}
- if (expected instanceof RegExp) {
+ if (Object.prototype.toString.call(expected) == '[object RegExp]') {
return expected.test(actual);
} else if (actual instanceof expected) {
return true;
View
10 test/simple/test-script-context.js
@@ -1,7 +1,8 @@
var common = require('../common');
var assert = require('assert');
-var Script = require('vm').Script;
+var vm = require('vm');
+var Script = vm.Script;
var script = new Script('"passed";');
common.debug('run in a new empty context');
@@ -20,6 +21,11 @@ result = script.runInContext(context);
assert.equal(3, context.foo);
assert.equal('lala', context.thing);
-
// Issue GH-227:
Script.runInNewContext('', null, 'some.js');
+
+// Issue GH-693:
+common.debug('test RegExp as argument to assert.throws');
+script = vm.createScript('var assert = require(\'assert\'); assert.throws(function() { throw "hello world"; }, /hello/);', 'some.js');
+script.runInNewContext({ require : require });
+
Something went wrong with that request. Please try again.