jedireza / aqua

:bulb: A website and user system starter
https://jedireza.github.io/aqua/
MIT License
1.38k stars 356 forks source link

verify a stub was called? #224

Closed walshe closed 7 years ago

walshe commented 7 years ago

is there any way with Lab/Code/Proxyquire to verify that a stub was called rather than the way I have done below ? want to avoid Sinon if I can

'use strict';

const Code = require('code');
const Lab = require('lab');
const Proxyquire = require('proxyquire');

const lab = exports.lab = Lab.script();

const NodeCronStub = {
    called : false,

    schedule : function (cronExpression, callback){

        this.called = true;
        console.log('dummy schedule');

    }

};

const LookerServiceStub = {
    called : false,
    getLookerReport : function (callback){

        this.called = true;
        callback(null,[{ foo: 'bar' }]);

    }
};
jedireza commented 7 years ago

This sounds like it falls outside the scope of this project. The short answer is there are a few ways to accomplish your goals. 😄

Here's an example of finishing a test when a stub is called: https://github.com/jedireza/aqua/blob/b3072fa11748a50ffbc16e0aee71ceca316c0cc2/test/client/pages/login/home/index.js#L76-L79

I found a relevant issue in the code repo issues here: https://github.com/hapijs/code/issues/66

Which led me to find a library some hapi contributors created called stand-in: https://github.com/continuationlabs/stand-in

I hope this helps. Happy hunting.