To search we can use find
or findOne
method to the model.
MarioChar.findOne({ name: "Mario"}).then(result => {
...
})
This code, finds the first match where name==="Mario"
Our finding_test.js file is
const assert = require('assert');
const MarioChar = require('../models/mariochar');
describe('Some demo tests', function(){
beforeEach(function(done){
var character = new MarioChar({
name: "Mario",
})
character.save().then(function(){
assert(character.isNew === false)
done();
})
})
//Create tests
it('Finding a record form the database', function(done){
MarioChar.findOne({ name: "Mario"}).then(result => {
assert(result.name === "Mario")
done();
})
})
})
Top comments (0)