node.js - Using mocha with TDD interface, ReferenceError -
i trying unittesting node via mocha , chai. familiar python's built in unittest
framework, using mocha's tdd interface, , chai's tdd style assertions.
the issue running mocha's tdd setup
function. running, variables declare within undefined
within tests.
here code:
test.js
var assert = require('chai').assert; suite('testing unit testing === testception', function(){ setup(function(){ // setup function, y u no define variables? // these work if move them individual tests, // not want :( var foo = 'bar'; }); suite('chai tdd style assertions should work', function(){ test('true === true', function(){ var blaz = true; assert.istrue(blaz,'blaz true'); }); }); suite('chai assertions using setup', function(){ test('variables declared within setup should accessible',function(done){ assert.typeof(foo, 'string', 'foo string'); assert.lengthof(foo, 3, 'foo`s value has length of 3'); }); }); });
which generates following error:
✖ 1 of 2 tests failed: 1) testing unit testing === testception chai assertions using setup variables declared within setup should accessible: referenceerror: foo not defined
you're declaring foo
in scope inaccessible other tests.
suite('testing unit testing === testception', function(){ var foo; // declare in scope tests can access. setup(function(){ foo = 'bar'; // make changes/instantiations here }); suite('this test able use foo', function(){ test('foo not undefined', function(){ assert.isdefined(foo, 'foo should have been defined.'); }); }); });
Comments
Post a Comment