Skip to content

Commit

Permalink
convert test/unit/runner.spec.js to unexpected
Browse files Browse the repository at this point in the history
Signed-off-by: Christopher Hiller <boneskull@boneskull.com>
  • Loading branch information
boneskull committed Apr 21, 2018
1 parent efe37f9 commit cf9b376
Showing 1 changed file with 39 additions and 45 deletions.
84 changes: 39 additions & 45 deletions test/unit/runner.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ describe('Runner', function () {
suite.addTest(new Test('im a test about bears', noop));
var newRunner = new Runner(suite);
newRunner.grep(/lions/);
expect(newRunner.total).to.equal(2);
expect(newRunner.total, 'to be', 2);
});

it('should update the runner.total with number of matched tests when inverted', function () {
Expand All @@ -33,7 +33,7 @@ describe('Runner', function () {
suite.addTest(new Test('im a test about bears', noop));
var newRunner = new Runner(suite);
newRunner.grep(/lions/, true);
expect(newRunner.total).to.equal(1);
expect(newRunner.total, 'to be', 1);
});
});

Expand All @@ -43,39 +43,33 @@ describe('Runner', function () {
suite.addTest(new Test('im another test about lions', noop));
suite.addTest(new Test('im a test about bears', noop));
runner.grep(/lions/);
expect(runner.grepTotal(suite)).to.equal(2);
expect(runner.grepTotal(suite), 'to be', 2);
});

it('should return the total number of matched tests when inverted', function () {
suite.addTest(new Test('im a test about lions', noop));
suite.addTest(new Test('im another test about lions', noop));
suite.addTest(new Test('im a test about bears', noop));
runner.grep(/lions/, true);
expect(runner.grepTotal(suite)).to.equal(1);
expect(runner.grepTotal(suite), 'to be', 1);
});
});

describe('.globalProps()', function () {
it('should include common non enumerable globals', function () {
var props = runner.globalProps();
expect(props).to.contain('setTimeout');
expect(props).to.contain('clearTimeout');
expect(props).to.contain('setInterval');
expect(props).to.contain('clearInterval');
expect(props).to.contain('Date');
expect(props).to.contain('XMLHttpRequest');
expect(props, 'to contain', 'setTimeout', 'clearTimeout', 'setInterval', 'clearInterval', 'Date', 'XMLHttpRequest');
});
});

describe('.globals()', function () {
it('should default to the known globals', function () {
expect(runner.globals().length).to.be.above(16);
expect(runner.globals().length, 'to be greater than', 16);
});

it('should white-list globals', function () {
runner.globals(['foo', 'bar']);
expect(runner.globals()).to.contain('foo');
expect(runner.globals()).to.contain('bar');
expect(runner.globals(), 'to contain', 'foo', 'bar');
});
});

Expand All @@ -101,8 +95,8 @@ describe('Runner', function () {
runner.checkGlobals();
global.foo = 'bar';
runner.on('fail', function (_test, err) {
expect(_test).to.equal(test);
expect(err.message).to.equal('global leak detected: foo');
expect(_test, 'to be', test);
expect(err.message, 'to be', 'global leak detected: foo');
delete global.foo;
done();
});
Expand Down Expand Up @@ -130,7 +124,7 @@ describe('Runner', function () {
return;
}
// verify that the prop isn't enumerable
expect(global.propertyIsEnumerable('XMLHttpRequest')).to.not.be.ok();
expect(global.propertyIsEnumerable('XMLHttpRequest'), 'to be', false);

// create a new runner and keep a reference to the test.
var test = new Test('im a test about bears', noop);
Expand All @@ -139,11 +133,11 @@ describe('Runner', function () {

// make the prop enumerable again.
global.XMLHttpRequest = function () {};
expect(global.propertyIsEnumerable('XMLHttpRequest')).to.be.ok();
expect(global.propertyIsEnumerable('XMLHttpRequest'), 'to be', true);

// verify the test hasn't failed.
newRunner.checkGlobals(test);
expect(test).to.not.have.key('state');
expect(test, 'not to have key', 'state');

// clean up our global space.
delete global.XMLHttpRequest;
Expand All @@ -155,8 +149,8 @@ describe('Runner', function () {
global.foo = 'bar';
global.bar = 'baz';
runner.on('fail', function (_test, err) {
expect(_test).to.equal(test);
expect(err.message).to.equal('global leaks detected: foo, bar');
expect(_test, 'to be', test);
expect(err.message, 'to be', 'global leaks detected: foo, bar');
delete global.foo;
delete global.bar;
done();
Expand All @@ -175,7 +169,7 @@ describe('Runner', function () {

// verify the test hasn't failed.
runner.checkGlobals(test);
expect(test).to.not.have.key('state');
expect(test, 'not to have key', 'state');

delete global.foo;
});
Expand All @@ -189,8 +183,8 @@ describe('Runner', function () {
global.foo = 'bar';
global.bar = 'baz';
runner.on('fail', function (test, err) {
expect(test.title).to.equal('im a test about lions');
expect(err.message).to.equal('global leak detected: bar');
expect(test.title, 'to be', 'im a test about lions');
expect(err.message, 'to be', 'global leak detected: bar');
delete global.foo;
done();
});
Expand Down Expand Up @@ -223,25 +217,25 @@ describe('Runner', function () {

describe('.fail(test, err)', function () {
it('should increment .failures', function () {
expect(runner.failures).to.equal(0);
expect(runner.failures, 'to be', 0);
runner.fail(new Test('one', noop), {});
expect(runner.failures).to.equal(1);
expect(runner.failures, 'to be', 1);
runner.fail(new Test('two', noop), {});
expect(runner.failures).to.equal(2);
expect(runner.failures, 'to be', 2);
});

it('should set test.state to "failed"', function () {
var test = new Test('some test', noop);
runner.fail(test, 'some error');
expect(test.state).to.equal('failed');
expect(test.state, 'to be', 'failed');
});

it('should emit "fail"', function (done) {
var test = new Test('some other test', noop);
var err = {};
runner.on('fail', function (test, err) {
expect(test).to.equal(test);
expect(err).to.equal(err);
expect(test, 'to be', test);
expect(err, 'to be', err);
done();
});
runner.fail(test, err);
Expand All @@ -251,7 +245,7 @@ describe('Runner', function () {
var test = new Test('helpful test', noop);
var err = 'string';
runner.on('fail', function (test, err) {
expect(err.message).to.equal('the string "string" was thrown, throw an Error :)');
expect(err.message, 'to be', 'the string "string" was thrown, throw an Error :)');
done();
});
runner.fail(test, err);
Expand All @@ -261,7 +255,7 @@ describe('Runner', function () {
var test = new Test('a test', noop);
var err = new Error('an error message');
runner.on('fail', function (test, err) {
expect(err.message).to.equal('an error message');
expect(err.message, 'to be', 'an error message');
done();
});
runner.fail(test, err);
Expand All @@ -271,7 +265,7 @@ describe('Runner', function () {
var test = new Test('a test', noop);
var err = { message: 'an error message' };
runner.on('fail', function (test, err) {
expect(err.message).to.equal('an error message');
expect(err.message, 'to be', 'an error message');
done();
});
runner.fail(test, err);
Expand All @@ -281,7 +275,7 @@ describe('Runner', function () {
var test = new Test('a test', noop);
var err = { x: 1 };
runner.on('fail', function (test, err) {
expect(err.message).to.equal('the object {\n "x": 1\n} was thrown, throw an Error :)');
expect(err.message, 'to be', 'the object {\n "x": 1\n} was thrown, throw an Error :)');
done();
});
runner.fail(test, err);
Expand All @@ -294,7 +288,7 @@ describe('Runner', function () {
2
];
runner.on('fail', function (test, err) {
expect(err.message).to.equal('the array [\n 1\n 2\n] was thrown, throw an Error :)');
expect(err.message, 'to be', 'the array [\n 1\n 2\n] was thrown, throw an Error :)');
done();
});
runner.fail(test, err);
Expand All @@ -313,7 +307,7 @@ describe('Runner', function () {
var test = new Test('a test', noop);

runner.on('fail', function (test, err) {
expect(err.message).to.equal('not evil');
expect(err.message, 'to be', 'not evil');
done();
});

Expand All @@ -323,31 +317,31 @@ describe('Runner', function () {

describe('.failHook(hook, err)', function () {
it('should increment .failures', function () {
expect(runner.failures).to.equal(0);
expect(runner.failures, 'to be', 0);
runner.failHook(new Test('fail hook 1', noop), {});
expect(runner.failures).to.equal(1);
expect(runner.failures, 'to be', 1);
runner.failHook(new Test('fail hook 2', noop), {});
expect(runner.failures).to.equal(2);
expect(runner.failures, 'to be', 2);
});

it('should augment hook title with current test title', function () {
var hook = new Hook('"before each" hook');
hook.ctx = { currentTest: new Test('should behave', noop) };

runner.failHook(hook, {});
expect(hook.title).to.equal('"before each" hook for "should behave"');
expect(hook.title, 'to be', '"before each" hook for "should behave"');

hook.ctx.currentTest = new Test('should obey', noop);
runner.failHook(hook, {});
expect(hook.title).to.equal('"before each" hook for "should obey"');
expect(hook.title, 'to be', '"before each" hook for "should obey"');
});

it('should emit "fail"', function (done) {
var hook = new Hook();
var err = {};
runner.on('fail', function (hook, err) {
expect(hook).to.equal(hook);
expect(err).to.equal(err);
expect(hook, 'to be', hook);
expect(err, 'to be', err);
done();
});
runner.failHook(hook, err);
Expand Down Expand Up @@ -383,7 +377,7 @@ describe('Runner', function () {
function fail () {
newRunner.runTest();
}
expect(fail).to.throwError('allow unhandled errors');
expect(fail, 'to throw', 'allow unhandled errors');
done();
});
});
Expand Down Expand Up @@ -417,7 +411,7 @@ describe('Runner', function () {
err.stack = stack.join('\n');

runner.on('fail', function (hook, err) {
expect(err.stack).to.equal(stack.slice(0, 3).join('\n'));
expect(err.stack, 'to be', stack.slice(0, 3).join('\n'));
done();
});
runner.failHook(hook, err);
Expand All @@ -440,7 +434,7 @@ describe('Runner', function () {
runner.fullStackTrace = true;

runner.on('fail', function (hook, err) {
expect(err.stack).to.equal(stack.join('\n'));
expect(err.stack, 'to be', stack.join('\n'));
done();
});
runner.failHook(hook, err);
Expand Down

0 comments on commit cf9b376

Please sign in to comment.