samedi 26 mars 2016

Unit test chained methods

How would I go about unit testing this? Essentially what I want to do is make sure that each method in the chain gets called X times. So for instance, I'd like to somehow be able to verify that bold() was called twice. Can I do this with sinon?

printer.on('ready', function() {
                printer
                    .indent(10)
                    .horizontalLine(16)
                    .bold(true)
                    .indent(10)
                    .printLine('first line')
                    .bold(false)
                    .inverse(true)
                    .big(true)
                    .right()
                    .printLine('second line')
                    .print(function() {
                        console.log('done printing');
                        //process.exit();
                    });
            });

Aucun commentaire:

Enregistrer un commentaire