In my MochaJS Test, my Firebase data is not sending when I have Promise-terminating code in, but it will push when the code is not present (but the test won't terminate). How do I fix that?
Note: The output is the same, except it will hang if the Promise-resolving code is not present.
Output:
OK Attempting to inject new event with id eidMAEfy
Attempting to set /db/events/eidMAEfy to {
... JSON DATA ...
}
* HANGS HERE IF RESOLVE NOT PRESENT*
Test.js:
describe('*NEW* Create New Event Test Suite', async function() {
this.timeout(0);
let new_event_req_body = unformalized_new_test_event();
let is_preexisting = false;
it('creates a new event', async function() {
return new Promise(async function (resolve, reject) {
try {
let res = await utils.create_new_event(new_event_req_body, is_preexisting); // ISSUE. Remove line & it posts the data (but never terminates test)
assert.isOk('Ok','Ok');
resolve('ok');
} catch (e) {
assert.fail(e);
reject('noo');
}
})
});
});
Utils.js
var create_new_event = async (req_body, is_preexisting) => {
return new Promise( async function(resolve, reject) {
// make json
let new_event_json = new_event_result(req_body);
if (!new_event_json) reject("Invalid Input");
let event_id = new_event_json.id;
ok_log("Attempting to inject new event with id " + event_id);
let dbstring = '/db/events/'+event_id;
log('Attempting to set ' + dbstring + ' to ' + prettify(new_event_json));
// post data
let re = root.ref(dbstring);
re.set(new_event_json);
resolve(event_id); // Always resolves
});
}