EvanBurchard / wish

node assertion library without special syntax
42 stars 4 forks source link

Basic assertion always outputs basic falsey message; characterization test always outputs TypeError #8

Closed jmbothe closed 7 years ago

jmbothe commented 7 years ago

basic info: OS: Ubuntu 17.04 node: v6.11.2 npm: v5.3.0 mocha: v3.5.0 wish: v1.0.0

I'm going to say thanks in advance BEFORE unleashing a deluge of code here :) THANKS!

I am currently reading/working through the Refactoring Javascript book (and seriously learning/enjoying), but I've run into this issue, starting on page 56, where we first install wish and run node check-hand.js.

I walked through the instructions leading up to this point twice, and got the same results. On the second try, I attempted npm init -f to setup a default package.json file (a step not mentioned in the book), but it didn't seem to make a difference.

the code:

var checkHand = function(){ };
var wish = require('wish');
wish(checkHand(['2-H', '3-C', '4-D', '5-H', '2-C'])==='pair');

The expected output:

WishError:
Expected "checkHand(['2-H', '3-C', '4-D', '5-H', '2-C'])" to be equal(===) to "'pair'"

the output I actually get:

WishError:
expression: "handleFalseWish()" evaluated to falsey 
at makeError (/home/jmbothe/webdev/refactoring-js-2/node_modules/wish/lib/wish.js:120:19)
at handleFalseWish (/home/jmbothe/webdev/refactoring-js-2/node_modules/wish/lib/wish.js:127:12)
at wish (/home/jmbothe/webdev/refactoring-js-2/node_modules/wish/lib/wish.js:143:15)
at Object.<anonymous> (/home/jmbothe/webdev/refactoring-js-2/check-hand.js:3:1)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.runMain (module.js:604:10)

I walked through the entire check-hand.js tutorial and got this message for every single assertion.

The other issue, on page 74, upon running mocha random-hand.js

the code:

const wish = require('wish');

var s = ['H', 'D', 'S', 'C'];
var v = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10', 'J', 'Q', 'K'];
var c = [];
var rS = function(){
  return s[Math.floor(Math.random()*(s.length))];
};
var rV = function(){
  return v[Math.floor(Math.random()*(v.length))];
};
var rC = function(){
  return rV() + '-' + rS();
};
var doIt = function(){
  c.push(rC());
  c.push(rC());
  c.push(rC());
  c.push(rC());
  c.push(rC());
};
doIt();
console.log(c);

describe('doIt()', function() {
  it('returns something', function() {
    wish(doIt(), true);
  });
});

Expected output: WishCharacterization: doIt() evaluated to undefined

Actual output:

TypeError: Cannot read property '1' of null
at characterizationMessage (node_modules/wish/lib/wish.js:76:62)
at handleCharacterization (node_modules/wish/lib/wish.js:131:21)
at wish (node_modules/wish/lib/wish.js:141:15)
at Context.<anonymous> (random-hand.js:28:5)

I added the other characterization tests from page 74, and they output the same.

b0rza commented 7 years ago

@jmbothe Had the same issue with node 6.9.2, upgrading to 8.4.0. made the characterization tests work. After that I got a characterization error with the correct evaluation as expected.

b0rza commented 7 years ago

Also loving the book so far! 🎉 💯

jmbothe commented 7 years ago

@b0rza thanks for the tip. Updating Node fixed everything and got me back on track. Much appreciated!