Upon getting to the “Multiple Filters” test in the test suite, my code either:
-
Doesn’t mark it as being passed despite my implementation working (and even when I try to force it to mark as completed by only having a “done();”)
-
“Skips” a test, changing the name of a test to the next one while not passing, e.g:
✓ One filter (110ms)
1) Multiple filters (test for multiple fields you know will be in the db for a return)
//here are actually some console logs I removed but will include later
DELETE /api/issues/{project} => text
✓ No _id
//This test should be "Valid _id", not a duplicate "No _id"
✓ No _id (110ms)
- Passes the test like it’s supposed to, but then throws an error and causes the subsequent tests to do either #1 or #2, e.g:
✓ Multiple filters (test for multiple fields you know will be in the db for a return) (39ms)
DELETE /api/issues/{project} => text
//A note here: I haven't done any of the Delete yet, so they are empty besides "done();"
1) No _id
/app/assertion-analyser.js:103
var body = body.match(/(?:browser\s*\.\s*)?assert\s*\.\s*\w*\([\s\S]*\)/)[0];
^
TypeError: Cannot read property '0' of null
at assertionAnalyser (/app/assertion-analyser.js:103:76)
at Runner.<anonymous> (/app/test-runner.js:69:23)
at Runner.emit (events.js:194:15)
at Runner.uncaught (/rbd/pnpm-volume/0efca928-96b8-47b7-9e5b-9cf6a28e8d4d/node_modules/.registry.npmjs.org/mocha/3.5.3/node_modules/mocha/lib/runner.js:720:10)
at process.uncaught (/rbd/pnpm-volume/0efca928-96b8-47b7-9e5b-9cf6a28e8d4d/node_modules/.registry.npmjs.org/mocha/3.5.3/node_modules/mocha/lib/runner.js:804:10)
at process.emit (events.js:189:13)
at process._fatalException (internal/bootstrap/node.js:496:27)
My code for the “One Filter” test is as follows:
test('One filter', function(done) {
chai.request(server)
.get('/api/issues/test')
.query({issue_title:'Title 2'})
.end(function(err, res){
console.log(res.body[0]);
console.log(res.body[1]);
assert.equal(res.status, 200);
assert.isArray(res.body);
assert.equal(res.body[0]['issue_title'], 'Title 2');
assert.equal(res.body[1]['issue_title'], 'Title 2');
done();
});
});
With the console.logs consisting of:
GET /api/issues/{project} => Array of objects with issue data
✓ No filter (1161ms)
{ _id: '5ead39038056522c2c9fed32',
issue_title: 'Title 2',
issue_text: 'text 2',
created_by: 'Owner',
assigned_to: '',
status_text: '',
open: true,
created_on: '2020-05-02T09:10:27.929Z',
updated_on: '2020-05-02T09:10:27.929Z' }
{ _id: '5ead39b463c6072d6b428a58',
issue_title: 'Title 2',
issue_text: 'text 2',
created_by: 'Owner',
assigned_to: '',
status_text: '',
open: true,
created_on: '2020-05-02T09:13:24.150Z',
updated_on: '2020-05-02T09:13:24.150Z' }
✓ One filter (110ms)
And my code for the “Multiple Filters” test is:
test('Multiple filters (test for multiple fields you know will be in the db for a return)', function(done) {
chai.request(server)
.get('/api/issues/test')
.query({_id: "5ead39038056522c2c9fed32", issue_title: 'Title 2'})
.end(function(err, res){
console.log(res.body);
console.log(res.body[0]['_id']);
console.log(res.body[0]['issue_title']);
assert.equal(res.status, 200);
assert.isArray(res.body);
assert.equal(res.body[0]["_id"], '5ead39038056522c2c9fed32');
assert.equal(res.body[0]['issue_title'], 'Title 2');
done();
});
Which logs to the console:
[ { _id: '5ead39038056522c2c9fed32',
issue_title: 'Title 2',
issue_text: 'text 2',
created_by: 'Owner',
assigned_to: '',
status_text: '',
open: true,
created_on: '2020-05-02T09:10:27.929Z',
updated_on: '2020-05-02T09:10:27.929Z' } ]
5ead39038056522c2c9fed32
Title 2
✓ Multiple filters (test for multiple fields you know will be in the db for a return) (39ms)
Again, I’d like to mention that sometimes it will pass, and sometimes it will not, even if all I have in the “end()” function is a done();
My “delete” test suite is only as follows:
suite('DELETE /api/issues/{project} => text', function() {
test('No _id', function(done) {
chai.request(server)
.get('/api/issues/test')
.end(function(err, res){
done();
});
});
test('Valid _id', function(done) {
chai.request(server)
.get('/api/issues/test')
.end(function(err, res){
done();
});
});
});
All of these different logs have been from only messing with the test suite itself; my code for the actual GET request has remained the same. I can provide it if it’s necessary to figure out what’s going on, but it’s my understanding that my code is working as intended as far as that goes, and that I’m doing something wrong in/with the code for the test suite. Any help would be greatly appreciated.