njsetn:injecting_dependencies_with_rewire

Possibilité de simuler des modules, pas que des sites. Et notamment des modules pas finis.

SUT : System Under Test

→ npmjs.com/package/rewire

npm install rewire –save-dev

// order-specs.js
var expect = require("chai").expect;
var rewire = require("rewire");
var order = rewire("../lib/order");
  describe("Ordering Items", function() {
    beforeEach(function() {
      this.testData = [
        {sku: "AAA", qty: 10},
        {sku: "BBB", qty: 0},
        {sku: "CCC", qty: 3},
      ];
      
      order.__set__("inventory", this.testData);
    });
    it("orded an item when there are enough in stock", function(done) {
      order.orderItem("CCC", 3, function() {
        // callback
        done();
      });
    });
njsetn/injecting_dependencies_with_rewire.txt · Last modified: 2016/03/28 15:09 by leo