it('should return widgets', function () {
const result = widgetFactory
.buildWidgets("WidgeCo", {
widgetMeta: {
gearTeethCount: 91,
handles: 3
},
presets: ['foo', 5, 12.3]
}, 17);
assert.equal(typeof result, object, 'Oh noes!');
});
Sometimes choosing the right place to start is the hardest thing you'll do all day
it('should return widgets', function () {
const companyName = "WidgeCo";
const widgetCount = 17;
const widgetSpec = {
widgetMeta: {
gearTeethCount: 91,
handles: 3
},
presets: ['foo', 5, 12.3]
}
const widgets = widgetFactory
.buildWidgets(companyName, widgetSpec, widgetCount);
assert.equal(typeof widgets, object, 'Oh noes!');
});
const signet = require('signet')();
signet.defineDuckType('widget', {
companyName: 'string',
handles: 'array<string>',
teethCount: 'int',
startupDisplay: 'string',
logMaxLength: 'int',
humFrequencyTolerance: 'number'
});
module.exports = signet;
function assertByType(type, value, errorMessage) {
const isCorrectType = signet.isTypeOf(type);
assert(isCorrectType(value), errorMessage);
}
it('should return widgets', function () {
const companyName = "WidgeCo";
const widgetCount = 17;
const widgetSpec = {
// Truncated for brevity
}
const widgets = widgetFactory
.buildWidgets(companyName, widgetSpec, widgetCount);
assertByType('array<widget>', widgets, 'We didn\'t get a widget array!');
});
function widgetSpecFactory () {
return {
widgetMeta: {
gearTeethCount: 91,
handles: 3
},
presets: ['foo', 5, 12.3]
};
}
dataMother.register('widgetSpec', widgetSpecFactory);
it('should return widgets', function () {
const companyName = "WidgeCo";
const widgetCount = 17;
const widgetSpec = dataMother.buildData('widgetSpec');
const widgets = widgetFactory
.buildWidgets(companyName, widgetSpec, widgetCount);
assertByType('array<widget>', widgets, 'We didn\'t get a widget array!');
});
it('should build a widget array using a company, widget spec and count', function () {
const companyName = "WidgeCo";
const widgetCount = 17;
const widgetSpec = dataMother.buildData('widgetSpec');
const widgets = widgetFactory
.buildWidgets(companyName, widgetSpec, widgetCount);
assertByType('array<widget>', widgets, 'We didn\'t get a widget array!');
});
const approvalsLocation = './test/approvals';
const approvalsConfigFactory = require('approvals-config-factory');
const approvalsConfig = approvalsConfigFactory.buildApprovalsConfig({
reporter: 'kdiff3'
});
module.exports = require('approvals')
.configure(approvalsConfig)
.mocha(approvalsLocation);
it('should build a widget array using a company, widget spec and count', function () {
const companyName = "WidgeCo";
const widgetCount = 17;
const widgetSpec = dataMother.buildData('widgetSpec');
const widgets = widgetFactory
.buildWidgets(companyName, widgetSpec, widgetCount);
assertByType('array<widget>', widgets, 'We didn\'t get a widget array!');
this.verifyAsJSON(widgets);
});
http://www.chrisstead.net/presentations/communicating-tests