My application code to test:
create(params) {
let result = {};
try {
result = await this.db.query('/* some query */');
} catch (e) {
throw new Error('Error creating User', e);
}
return this._getById(result.insertId);
}
I have the _getById
method in the same class which does exactly what it says...
And my current test (running through Ava):
test('it should create a user', async t => {
const db = mock({
query: () => {
},
});
const userObj = {
// some params
};
const user = new Users({
db: db.object,
});
const call = {
request: userObj,
};
const result = await user.create(call);
// test?
});
If I try and test anything based off of the result
variable, ie. the newly created User, I receive the error "Cannot read property 'insertId' of undefined"
. What is my best option with Sinon to test that this create
method will return a newly created "user"?