-
Notifications
You must be signed in to change notification settings - Fork 139
Closed
Description
I am not sure this is a correct place to ask a question. But I see git issues tab is really active and hope someone can help me out ASAP.
category.js to be tested
'use strict';
module.exports = (client) => {
const filter = (done) => {
client.getEntries({
content_type: 'category',
select: 'fields'
}).then(res => {
const categories = res.items.map((x) => {
return {
id: x.sys.id,
name: x.fields.name
};
});
done(null, categories);
}).catch(err => {
console.log(err);
done(err, null);
});
};
return {
filter
};
};My current test - client is an instance created from a constructor provided by 3rd library.
'use strict'
const test = require('tap').test;
const td = require('testdouble');
const fs = require('fs');
const category = require('../category');
const setup = () => {
return JSON.parse(fs.readFileSync(`${__dirname}/entries.sample.json`, 'utf-8'));
};
test('get all categories', (t) => {
const content = setup();
let client = {
getEntires: () => {
return content;
}
};
client = td.object(client);
const _category = category(client);
const filter = _category.filter;
// client.getEntires = function() {
// return content;
// };
const _filter = td.function('filter');
td.when(_filter).thenCallback(null, {
id: 'xxx',
name: 'yyy'
});
// td.verify(_done(content));
// const _category = category(client);
// td.when(client.getEntires()).thenCallback(null, {
// id: 'xxx',
// name: 'xxx'
// });
// _category.filter(_done);
t.end();
});My question is as follow
How do I test the case that given the response from client.getEntries promise resolve callback, the callback function done is executed with second argument filled up with correct value like {id: 'xxx', name: 'yyyy'}
Also, is my design too difficult to write a test?
Many thanks in advance.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels