javascript - Cucumber Js callback issue? or feature issue? -
i'd write feature this:
scenario: new singleton create when new, unmatchable identity received new tin record should created , new bronze record should created , new gold record should created
which tie steps this:
definesupportcode(function ({ before, given, then, when }) { var expect = require('chai').expect; var chancegenerator = require('./helpers/chancegenerator') var request = require('./helpers/requestgenerator') let identmap; // reset identmap before each scenario before(function () { identmap = []; }); // should generate valid identity // persist in local variable can tested in later steps // , persist db via public endpoint when('a new, unmatchable identity received', function (callback) { identmap.push(chancegenerator.identity()); request.pubpostidentity(identmap[identmap.length-1], callback); }); // use local variable retrieve tin persisted // validate tin persisted props should have then('a new tin record should created', function (callback) { request.pubgetidentity(identmap[identmap.length-1], callback); // var self = this; // request.pubgetidentity(identmap[identmap.length-1], callback, () => { // console.log('never gets here...'); // self.callback(); // callback(); // }); // request.pubgetidentity(identmap[identmap.length-1], (callback) => { // console.log('never gets here...'); // self.callback(); // callback(); // }); });
the issue i'm having can't in callback. i'd able verify response has right data.
here relevant excerpts helper files:
var pubpostidentity = function (ident, callback) { console.log('pubidentity'); var options = { method: 'post', url: 'http://cucumber.utu.ai:4020/identity/' + ident.platform + '/' + ident.platformid, headers: { 'x-consumer-custom-id': ident.botid + '_' + ident.botid }, body: json.stringify(ident) }; console.log('ident: ', ident); request(options, (err, response, body) => { if (err) { console.log('pubpostidentity: ', err); callback(err); } console.log('pubpostidentity: ', response.statuscode); callback(); }); } // accept identity , retrieve staging via identity public endpoint var pubgetidentity = function (ident, callback) { console.log('pubgetidentity'); var options = { method: 'get', url: 'http://cucumber.utu.ai:4020/identity/' + ident.platform + '/' + ident.platformid, headers: { 'x-consumer-custom-id': ident.botid + '_' + ident.botid } }; request(options, (err, response) => { if (err) { console.log('pubgetidentity: ', err); callback(err); } console.log('pubgetidentity: ', response.body); callback(); }); }
something considering option re-write feature fit different step definition structure. if re-wrote feature this:
scenario: new singleton create when new, unmatchable 'tin_record' received identity record should created when identity record retreived 'tin' new 'tin' should created when identity record retreived 'bronze' new 'bronze' should created when identity record retreived 'gold' new 'gold' should created
i believe bypasses instep callback issue wrestling with, hate breakdown of feature. makes feature less readable , comprehensible business.
so... question, summary feature presented first, written wrong? trying step definitions shouldn't? or lack of js skills shining bright, , should doable, i'm screwing callbacks?
firstly, i'd rewritten feature wrong. should never go in progression given, when, then. going when, wrong.
given used setting preconditions. when used actual test. used assertions. each scenario should single test, should have few when clauses. if want, can use scenario outlines mix several similar tests together.
in case, recommend take first principles , see if works. build out working.
i suspect in case problem in exception being thrown isn't handled. try rewriting use promises instead, rejected on error. gives better error reporting.
Comments
Post a Comment